1.0.0 • Published 4 years ago

for-range v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

For Range Travis CI Build Status

Simplified syntax for a for loop.

NPM Badge

Install

npm install for-range

Usage

const forRange = require("for-range");

forRange({ min: 2, max: 10, step: 2 }, (i) => {
    if (i === 4) return; // Skip for 4
    if (i === 8) return false; // Stop for loop at 8
    console.log(i);
});

// Native JS equaivent
for (let i = 2; i <= 10; i += 2) {
    if (i === 4) continue;
    if (i === 8) break;
    console.log(i);
}

API

forRange(options, callback)

options

Type: object

min

Type: number\ Default: 0

The number to start the for loop at.

max

Type: number

The number to end the for loop at.

step

Type: number\ Default: 1

The amount to add to the number each iteration

callback

Type: function

The callback to trigger for each iteration.