basic/doc/statements/
for.rs

1/*!
2# `FOR <variable>=<x> TO <y> [STEP <z>]`
3Where x, y, and z are expressions.
4## Purpose
5Used with `NEXT` to repeat execution of statements
6while iterating over a sequence of numbers.
7
8## Remarks
9If we wanted the numbers 1,3,5,7 we would write `FOR I=1 TO 7 STEP 2`.
10On the first iteration, 1 will be assigned to variable I.
11Statements execute until a `NEXT` statement.
12On subsequent iterations, the variable I gets 2 added to it.
13If the result exceeds 7 the loop breaks.
14Otherwise the statements get executed again.
15
16The first iteration will evaluate x, then y, then z.
17Newer versions of BASIC evaluate z first.
18
19The first iteration always executes even if starting past the end.
20Newer versions of BASIC may skip the first iteration.
21
22## Example 1
23```text
2410 FOR I=1 TO 7 STEP 2
2520 PRINT "HELLO WORLD";i
2630 NEXT I
27RUN
28HELLO WORLD 1
29HELLO WORLD 3
30HELLO WORLD 5
31HELLO WORLD 7
32```
33
34## Example 2
35```text
3610 FOR X=1 TO 2
3720 FOR Y=5 TO 6
3830 PRINT X;Y
3940 NEXT Y,X
40RUN
41 1  5
42 1  6
43 2  5
44 2  6
45```
46
47*/