next up previous contents index
Next: A loop with forever Up: Loops: Previous: A loop with while   Contents   Index


A loop with foreach

This is the syntax for the primitive foreach:
foreach variable_name list or word instructions
The variable has for successive value the item from a list, or the character from a word.The instructions are repeated for each value of the variable.
foreach "i "XLOGO [print :i]
X
L
O
G
O
foreach "i [a b c] [print :i]
a
b
c

make "sum 0 foreach "i 12345 [make "sum :sum+:i] print :sum
15



Loïc 2008-06-08