User`s manual
4-12
FOR-NEXT loops may be "nested":
10 FOR I=1TO3
20 PRINT"OUTER LOOP"
30 FOR J=1 TO 2
40 PRINT" INNER LOOP"
50 NEXT J
60 NEXT I
RUN
OUTER LOOP
INNER LOOP
INNER LOOP
OUTER LOOP
INNER LOOP
INNER LOOP
OUTER LOOP
INNER LOOP
INNER LOOP
Note that each NEXT statement specifies the appropriate counter variable;
however, this is just a programmer's convenience to help keep track of the
nesting order. The counter variable may be omitted from the NEXT
statements. But if you
do
use the counter variables, you
must
use them in
the right order; i.e., the counter variable for the innermost loop must come
first. It is also advisable to specify the counter variable with NEXT
statements when your program allows branching to program lines outside the
FOR-NEXT loop.
Another option with nested NEXT statements is to use a counter variable
list.
Delete line 50 from the above program and change line 60:
60 NEXT J,I
Loops may be nested 3-deep, 4-deep, etc. The only limit is the amount of
memory available.










