BASIC commands
PROGRAMMING MANUAL
85
Revi
si
on 3.0
3.2.124 FOR..TO..STEP..NEXT
/i
Type
Program control command
Syntax
FOR variable = start TO end [STEP increment]
commands
NEXT variable
Description
The
FOR ... NEXT
loop allows the program segment between the
FOR
and
the
NEXT
statement to be repeated a number of times.
On entering this loop, the variable is initialized to the value of start and the
block of commands is then executed. Upon reaching the
NEXT
command, the
variable is increased by the increment specified after
STEP
. The
STEP
value
can be positive or negative, if omitted the value is assumed to be 1.
While variable is less than or equal to end, the block of commands is repeat-
edly executed until variable is greater than end, at which time program execu-
tion will continue after
NEXT
.
Note:
FOR ... NEXT
statements can be nested up to 8 levels deep in a BASIC
program.
Arguments
•
variable
A BASIC expression.
•
start
A BASIC expression.
•
end
A BASIC expression.
•
increment
A BASIC expression.
•
commands
One or more BASIC commands.
Example
FOR opnum = 8 TO 13
OP(opnum,ON)
NEXT opnum
This loop turns on outputs 8 to 13.
Example
loop:
FOR dist = 5 TO -5 STEP -0.25
MOVEABS(dist)
GOSUB pick_up
NEXT dist
The
STEP
increment can be positive or negative.
Example
loop1:
FOR l1 = 1 TO 8
loop2:
FOR l2 = 1 TO 6
MOVEABS(l1*100,l2*100)
GOSUB 1000
NEXT l2
NEXT l1
FOR..TO..STEP..NEXT
statements can be nested (up to 8 levels deep) pro-
vided the inner
FOR
and
NEXT
commands are both within the outer
FOR..TO..STEP..NEXT
loop.
See also
REPEAT..UNTIL
,
WHILE..WEND
.
I52E-EN-03.book Seite 85 Freitag, 29. Juni 2007 11:55 11