FOR
Runs a block for each of a run of numbers.
Syntax
FOR name = from TO to BEGIN … END
FOR name = from TO to STEP step BEGIN … END
| Argument | Meaning |
|---|---|
| name | The variable that takes each number in turn. |
| from | The first number: an expression. |
| to | The last: the loop stops when the next number would go past it. |
| step | What is added each time round (1 if left out). It can be less than 0, to count down; it can't be 0. |
DO may go before BEGIN: FOR I = 1 TO 5 DO BEGIN … END.
Examples
FOR I = 0 TO L STEP 50 BEGIN
P10 = [I, 0]
P11 = [I, W]
LINE P10, P11
END

Lines across the box every 50, and as many as fit: change L and there are more, or fewer.
FOR A = 0 TO 330 STEP 30 BEGIN
P10 = POLAR(P0, A, 100)
P11 = POLAR(P0, A, 120)
LINE P10, P11
END
Twelve ticks round P0, as on a clock face.
Notes
from, to and step are worked out once, when the loop starts. The last number is included when the steps land on
it (allowing for rounding: FOR I = 0 TO 1 STEP 0.1 runs 11 times).
BREAK leaves the loop; CONTINUE goes on to the next number.
See also: Blocks and control flow, FOREACH, WHILE.