Iteration

Arc provides a number of macros to iterate over code multiple times.
while, until, whilet,
whiler, and loop permit iteration subject to a
condition.
drain iterates over an expression, collecting the values.
for and repeat iterate a specified
number of times. forlen, each,
noisy-each, on, and ontable iterate over a sequence.

Iteration

whiletest [body ...]

Executes body repeatedly while test is true. The test is evaluated before each execution of body.

>(let x 0 (while (< x 3) (prn x) (++ x)))
0
1
2
nil

untiltest [body ...]

Executes body repeatedly until test is true. The test is evaluated before each execution of body. until is the opposite of while.

>(let x 0 (until (> x 3) (prn x) (++ x)))
0
1
2
3
nil

whiletvar test [body ...]

Executes body repeatedly while test is
true. The value of test is assigned to var on each iteration, for use in the
body. Typically test obtains a new value from some source, and whilet is used
to loop until nil is obtained.

>(w/instring s "abc" (whilet c (readc s) (prn c)))
a
b
c
nil

whilervar expr endval [body ...]

Executes body repeatedly while expr
is not endval. The value of expr is assigned to var on each iteration.