The module Loop contains a few higher-order procedures that represent recursive versions of commonly known iteration schemes.
{for +I1 +I2 +I3 +P}
applies the unary P concurrently to integers from I1 to I2 proceeding in steps of size I3. For example,{Loop.for 1 11 3 Browse}displays the numbers 1, 4, 7, and 10 in the browser window, whereas{Loop.for 11 1 ~3 Browse}displays the numbers 11, 8, 5, and 2.
{forThread +I1 +I2 +I3 +P X ?Y}
applies ternary P concurrently to the integers from
I1 to I2 proceeding in
steps of size I3.
Additionally, an initial value X is threaded through the
applications of P, yielding the result Y.
For example,
{Loop.forThread 1 10 1 fun {$ In I} I*I + In end 0 Sum}
constrains Sum to the sum of the first 10 square numbers.
{whileDoB X +P1 +P2 ?Y}
applies the binary procedure P2 concurrently to values X
as long as P1 X
yields True (or holds for the non boolean version), proceeding
with Y= P2 X
each time. If P1 X
yields False (or fails), Y=X is elaborated.
For example,
{Loop.whileDoB 19 IsOddB fun {$ X} X div 2 end Z}
constrains Z to 4.
{repeatUntilB X +P1 +P2 ?Y}
applies the binary procedure P2 concurrently to values starting
with X until P1 X
yields True (or holds for the non boolean version), proceeding with
Y= P2 X each time. For example,
{Loop.repeatUntilB 19 IsEvenB fun {$ X} X div 2 end Z}
constrains Z to 4.
{multiFor +Xs +P}
applies the unary procedure P concurrently to lists of loop
indices (one element for each nested loop)
as described by the variable Xs.
Xs is a list containing tuples of the form
I1#I2#I3 specifying a loop by its start value I1, upper limit I2
and step size I3 similar to the procedure Loop.for.
For example,
{Loop.multiFor [1#5#1 10#20#2] proc {$ [X Y]} {Browse X#Y} end}
displays the tuples 1 # 10, 1 # 12, ... , 5 # 20
in the browser.
{multiForThread +Xs +P X ?Y}
applies the unary procedure P concurrently to lists of loop indices (one element for each nested loop) as described by the variable Xs (just as explained for Loop.multiFor). Additionally, an initial value X is threaded through the applications of P, yielding the result Y (cf. Loop.for vs. Loop.forThread).