loop ( ... pred: ( ... -- ... ? ) -- ... )
Factor handbook » The language » Combinators » Looping combinators

Prev:do ( pred body -- pred body )


Vocabulary
kernel

Inputs
preda quotation


Outputs
None

Word description
Calls the quotation repeatedly until it outputs f.

Examples
Loop until we hit a zero:
USING: kernel random math io ; [ "hi" write bl 10 random zero? not ] loop
hi hi hi

A fun loop:
USING: kernel prettyprint math ; 3 [ dup . 7 + 11 mod dup 3 = not ] loop drop
3 10 6 2 9 5 1 8 4 0 7


Definition

: loop ( ... pred: ( ... -- ... ? ) -- ... )
[ call ] keep [ loop ] curry when ; inline recursive