Propeller Manual

Table Of Contents
NEXT – Spin Language Reference
Page 140 · Propeller Manual v1.1
NEXT
Command: Skip remaining statements of REPEAT loop and continue with the next loop
iteration.
((PUB PRI))
NEXT
Explanation
NEXTis one of two commands (NEXT and T QUIT) that affect REPEATT loops. NEXT causes any
further statements in the
T
REPEATT loop to be skipped and the next iteration of the loop to be
started thereafter.
Using NEXT
NEXT is typically used as an exception case, in a conditional statement, in REPEAT loops to
move immediately to the next iteration of the loop. For example, assume that
X is a variable
created earlier and
Print() is a method created elsewhere that prints a value on a display:
repeat X from 0 to 9 'Repeat 10 times
if X == 4
next 'Skip if X = 4
byte[$7000][X] := 0 'Clear RAM locations
Print(X) 'Print X on screen
The above code iteratively clears RAM locations and prints the value of X on a display, but
with one exception. If
X equals 4, the IF statement executes the NEXT command which causes
the loop to skip remaining lines and go right to the next iteration. This has the effect of
clearing RAM locations $7000 through $7003 and locations $7005 through $7009 and
printing 0, 1, 2, 3, 5, 6, 7, 8, 9 on the display.
T
The
NEXT command can only be used within a REPEAT loop; an error will occur otherwise.