FOR
...
NEXT loops may
be
nested. Each nested loop must have a different
index variable name. A nested loop
must
be
wholly
contained
within
the next
outer loop; at most. the loops can end at the same point.
The index variable may optionally
be
included in the NEXT statement. This
may
be
advisable
to
improve the readability of the program when there are nested
FOR
...
NEXT loops. A single NEXT statement
is
permissible for nested loops
that
end at the same point. The NEXT statement
would
then take the following form:
NEXT
indexl.index2
....
A
FOR
...
NEXT loop may contain subroutine calls.
but
the loop cannot ter-
minate inside a called subroutine. Both
FOR
...
NEXT loops and subroutine calls
use the Stack
(see
Chapter
6).
The
FOR
...
NEXT loop
will
always
be
executed at least once. even when the
beginning index value
is
beyond the end index value range. If the NEXT statement
is
omitted and no subsequent NEXT statements are found. the loop
is
executed
once.
The start. end. and increment values are read only once. at the first execu-
tion of the
FOR
statement. Vou cannot change these values inside the loop. Vou
can change the value of the index variable
within
the loop. This may
be
used
to
terminate a
FOR
...
NEXT loop before the end value
is
reached: set the index to
the end value. and on the next pass the loop
will
terminate itself. Do not
jump
out
of the
FOR
...
NEXT loop
with
a
GOTO.
Examples:
10
FOR
IN
= 0
TO
100
40
NEXT
IN
100
FOR
X =
A+14
TO
C-64+0/2
STEP
4
150 NEXT X
60
FOR
Al
= 50
TO
0
STEP
-1
90 NEXT
128