FOR-
TO-STEP
FOR-NEXT
loops may be "nested"; that is, one
FOR·NEXT
loop
may be contained wholly within another. You must use caution,
however, to observe the following conventions:
•
Each
FOR·TO·STEP
statement must be paired with a
NEXT
statement.
• Different control-variables
must
be used
for
each nested
FOR-NEXT
loop.
•
If
a
FOR-NEXT
loop contains any portion of another
FOR-NEXT
loop, it must contain
a11
of
the second FOR-
NEXT
loop.
Otherwise, the computer will stop running your program and print
the error message "CAN'T DO THAT
IN
xx" if a
FOR-NEXT
loop
overlaps another.
You
may branch out of a
FOR-NEXT
loop using
GOTO
and
IF-
THEN
-ELSE
statements,
but
you
may
not
branch
into
a
FOR-
NEXT
loop using these statements.
You
may use
GOSUB
statements to leave a
FOR-NEXT
loop and return. Be sure you do
nul
use
the
same
control-va.riable for
any
FOR-NEXT
loops
you
may have
in
your subroutines.
User's Reference Guide
Examples:
>NEW
>100
REM
fIND
THE
LOWEST
THREE
DIGIT
NUMBER
EQUAL
TO
THE
SUM
Of
THE
CUBES
OF
ITS
DIGITS
>110
FOR
HUND=1
TO
9
>120
FOR
TENS=O
TO
9
>130
FOR
UNITS=O
TO
9
>140 SUM=100*HUND+10*TENS+UNI
TS
>150
If
SUM(>HUNDA3+TENSA3+UN
lTSA3
THEN
180
>160
PRINT
SUM
>170
GOTD
210
>180
NEXT
UNITS
>190
NEXT
TENS
>200
NEXT
HUND
>210
END
>RUN
153
**
DONE
**
>NEW
>100
fOR
1=1
TO
3
>110
PRINT
I
>120
GOSUB
140
>1~o
NEXT
I
>140
FOR
1=1
TO
5
>150
PRINT
I;
>160
NEXT
I
>170
RETURN
>180
END
>RUN
1
1 2
345
*
CAN'T
DO
THAT
IN
130
II-55