is => the final value, then the first state-
ment following the FOR statement is
executed. Otherwise, the statement
following the NEXT statement is executed.
All FOR loops execute the statements
between the FOR and the NEXT at least
once, even in cases like FOR V=1 TO 0.
Note that expressions (formulas) may be 315 FOR V=10*N TO
used for the initial, final and step values 3.4/Q STEP SQR(R)
in a FOR loop. The values of the expres-
sions are computed only once, before the
body of the FOR...NEXT loop is
executed.
When the statement after the NEXT is 320 FOR V=9 TO 1
executed, the loop variable is never equal STEP -1
to the final value, but is equal to whatever
value caused the FOR...NEXT loop to
terminate. The statements between the
FOR and its corresponding NEXT in both
examples above (310 and 320) would be
executed nine times.
Error: do not use nested FOR...NEXT 330 FOR W=1 TO 10:
loops with the same index variable. FOR W=1 TO 5:NEXT
W:NEXT W
FOR loop nesting is limited only by the
available memory. (See Appendix C.)
STATEMENT SYNTAX/FUNCTION EXAMPLE
GOSUB GOSUB line number 10 GOSUB 910
Branches to the specified statement (910)
until a RETURN is encountered; when a
branch is then made to the statement after
the GOSUB. GOSUB nesting is limited
only by the available memory.
STATEMENT SYNTAX/FUNCTION EXAMPLE
GOTO GOTO line number 50 GOTO 100
Branches to the statement specified.
STATEMENT SYNTAX/FUNCTION EXAMPLE
IF...GOTO IF expression GOTO line number ... 32 IF X<=Y+23.4
Equivalent to IF...THEN, except that GOTO 92
IF...GOTO must be followed by a line
number, while IF...THEN can be
followed by either a line number or
another statement.
STATEMENT SYNTAX/FUNCTION EXAMPLE
IF...THEN IF expression THEN line number ... IF X<10 THEN 5
Branches to specified statement if the
relation is True.
Executes all of the statements on the 20 IF X<0 THEN PRINT
remainder of the THEN if the relation "X LESS THAN 0"
is True.
WARNING: The "Z=A" will never be 25 IF X=5 THEN 50:Z=A
executed because if the relation is true,
BASIC will branch to line 50. If the
relation is false BASIC will proceed to
to the line following line 25.