Introduction #
The Propeller 2 SPIN2 language has a new feature added in version 52 to extend the flexibility of the REPEAT loop control commands, NEXT and QUIT.
Explainer #
Within REPEAT constructs, NEXT and QUIT are two special instructions which can be used to change the course of execution. NEXT will immediately branch to the point in the REPEAT construct where the decision to loop again is made, while QUIT will exit the REPEAT construct and continue after it.
These instructions are usually used conditionally:
REPEAT
{indented code}
IF {condition} - Optionally force the next iteration of the REPEAT
NEXT
{indented code}
IF {condition} - Optionally quit the REPEAT
QUIT
{indented code}
NEXT and QUIT can each be followed by an integer value 1..16 to alter the nesting level at which they are to occur.
If no integer value is expressed, the default value of 1 is used, which means the current nesting level. The value 2 would mean the outer nesting level, while three would mean the next outer nesting level, and so on.
Nested Example #
REPEAT
{outer loop code}
REPEAT 5
{indented code}
IF {condition} - Optionally force the next iteration of the REPEAT
NEXT
{indented code}
IF {condition} - Optionally quit the OUTER REPEAT loop, 2 nested levels up
QUIT 2
{indented code}
Resources #
Parallax Propeller 2 - Spin2 Language Documentation