floop

Functional for-loop implementation in JS

npm install floop
14 downloads in the last week
28 downloads in the last month

floop

Functional for-loop implementation in JS

Allows you to write for loops without those pesky semicolons

Installation

npm install floop

Usage

var floop = require('floop')
floop(condition ,body ,final_expression ,initialization ,context)

Examples:

;(function () {
  var i
  function initialization () {
    i = 0
  }

  function condition () {
    return i < 2
  }

  function final_expression () {
    i++
  }

  function body () {
    console.log(i)
  }

  floop(condition ,body ,final_expression ,initialization)
})()
var context = {}
function initialization (context) {
  context.i = 0
  context.sum = 0
}

function condition (context) {
  return context.i < 2
}

function final_expression (context) {
  context.i++
}

function body (context) {
  context.sum += i
  return context.sum
}

  floop(condition ,body ,final_expression ,initialization ,context)
;(function () {
  var i = 0
  floop( function () { return i < 5 }
       , function () { console.log(i) }
       , function () { i++ }
       )
})()
//nice minimal syntax
;(function () {
  var i = 0
  floop(function () { return i < 5 } ,function () {
    console.log(i)
    i++
  })
})()
//loops forever
floop()

License

AGPL

Final note

Seriously, never use this.

npm loves you