[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
NEXT End Definition of FOR/NEXT Loop
FOR counter = start TO end [STEP increment]
.
. [statements]
.
NEXT [counter [,counter...]]
Terminates the definition of a FOR/NEXT loop.
counter A numeric variable to be used as the loop counter. All
numeric types are allowed, but the loop executes fastest
if counter is an integer variable.
start A numeric expression; the starting value of counter.
end A numeric expression; the ending value of counter.
increment A numeric expression; the value by which counter is
incremented or decremented with each iteration of the
loop. Defaults to +1.
----------------------------------------------------------------------
Notes: BASIC begins processing of the FOR/NEXT block by setting
counter equal to start. Then, if increment is positive and
counter is less than end, the statements between the FOR
statement and the NEXT statement are executed. When the
NEXT statement is encountered, counter is increased by
increment, and the process is repeated. Execution passes
to the statement following the NEXT statement if counter
is equal to or greater than end.
If increment is negative, execution of the FOR/NEXT loop
is terminated whenever counter becomes equal to or less
than end.
If increment is 0, execution of the FOR/NEXT loop
continues until Ctrl-Break is pressed (unless one of the
repeated instructions itself increments counter).
Note that changes made within the FOR/NEXT loop to counter
affect the number of times the loop instructions are
executed; changes made to start, end, and increment,
however, do not have this effect.
There must be one and only one NEXT statement for each FOR
statement. Inclusion of counter in the NEXT statement is
optional; if counter is omitted, its value is assumed to
be that of counter in the most recent FOR statement.
FOR/NEXT loops may be nested within one another. Each FOR
must be given a unique counter value and each nested FOR
must have its NEXT statement appear within the enclosing
FOR-NEXT block.
Nested loops that have a common termination point may use
a single NEXT statement with values of counter matching
the values for each FOR statement.
See Also:
DO
FOR
LOOP
WEND
WHILE
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson