Propeller (inglés)

Page 140

NEXT – Spin Language Reference 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 QUIT) that affect REPEAT loops. NEXT causes any further statements in the REPEAT loop to be skipped and the next iteration of the loop to be started thereafter. T

T

T

T

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 if X == 4 next byte[$7000][X] := 0 Print(X)

'Repeat 10 times 'Skip if X = 4 'Clear RAM locations '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.

Page 140 · Propeller Manual v1.1


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.