for-range
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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 (=== 4) return; // Skip for 4
    if (=== 8) return false; // Stop for loop at 8
    console.log(i);
});
 
// Native JS equaivent
for (let i = 2; i <= 10; i += 2) {
    if (=== 4) continue;
    if (=== 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.

/for-range/

    Package Sidebar

    Install

    npm i for-range

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • richienb