User`s manual
4-10
FOR
counter = exp
TO
exp
STEP
exp
NEXT
counter
Opens an iterative (repetitive) loop so that a sequence of program statements
may be executed over and over a specified number of times. The general form
is (brackets indicate optional material):
line
#
FOR
counter-variable = initial value
TO
final value
[
STEP
increment
]
.
.[
program statements
]
.
line
#
NEXT
[
counter-variable
]
In the FOR statement,
initial value, final value
and
increment
can be
constants, variables or expressions. The first time the FOR statement is
executed, these three are evaluated and the values are saved; if the variables
are changed by the loop, it will have no effect on the loop's operation.
However,
the counter variable must not be changed
or the loop will not
operate normally.
The FOR-NEXT-STEP loop works as follows: the first time the FOR
statement is executed, the counter is set to the "initial value." Execution
proceeds until a NEXT statement is encountered. At this point, the counter is
incremented by the amount specified in the STEP
increment
. (If the
increment
has a negative value, then the counter is actually decremented.) If
STEP
increment
is not used, an increment of 1 is assumed.
Then the counter is compared with the
final value
specified in the FOR
statement. If the counter is greater than the
final value
, the loop is completed
and execution continues with the statement following the NEXT statement.
(If
increment
was a negative number, loop ends when counter is
less
than
final value
.) If the counter has not yet exceeded the
final value
, control passes
to the first statement after the FOR statement.
Example Programs:
10 FOR I=10 TO 1 STEP -1
20 PRINT I;
30 NEXT
RUN
10 9 8 7 6 5 4 3 2 1
READY
>_
--------------------------------------










