Loops/Increment loop index within loop body: Difference between revisions

m
(Realize in F#)
Line 435:
// unfold is sort of a loop incremented by 1 in this case
let fG n=Seq.unfold(fun n->Some(n,(n+1UL))) n|>Seq.find(fN)
// unfold is sort of a loop with fG as an internal loop incremented by twice the exit value of the internal loop in this case.
Seq.unfold(fun n->let n=fG n in Some(n,n+n)) 42UL|>Seq.take 42|>Seq.iteri(fun n g->printfn "%2d -> %s" (n+1) (cUL g))
</lang>
Line 483:
42 -> 99,504,028,301,131
</pre>
 
=={{header|Factor}}==
Explicit loop indices are non-idiomatic, but Factor is certainly capable of using them. Factor has a for loop near-equivalent, <code><range> [ ] each</code>, but since it doesn't mesh well with mutation, a while loop is used.
2,172

edits