Propeller Manual

Table Of Contents
2: Spin Language Reference – REPEAT
Propeller Manual v1.1 · Page 193
After the 10
th
iteration of the loop, X equals 10, making the condition while X < 10 false and
the loop terminates.
This loop is said to use “positive” logic because it continues “
WHILE” a condition is true. It
could also be written with “negative” logic using
UNTIL, instead. Such as:
X := 0
repeat until X > 9 'Repeat until X is greater than 9
byte[$7000][X] := 0 'Increment RAM value
X++ 'Increment X
The above example performs the same way as the previous, but the REPEAT loop uses negative
logic because it continues “
T
UNTIL” a condition is true; i.e: it continues while a condition is
false.
In either example, if
X was equal to 10 or higher before the first iteration of the REPEAT loop,
the condition would cause the loop to never execute at all, which is why we call it a zero-to-
many loop.
The
REPEAT form described by syntax 4 is very similar to syntax 3, but the condition is tested
at the end of every iteration, making it a one-to-many loop. For example:
X := 0
repeat
byte[$7000][X] := 0 'Increment RAM value
X++ 'Increment X
while X < 10 'Repeat while X is less than 10
This works the same as the previous examples, looping 10 times, except that the condition is
not tested until the end of each iteration. However, unlike the previous examples, even if
X
was equal to 10 or higher before the first iteration, the loop would run once then terminate,
which is why we call it a one-to-many loop.
Other REPEAT Options
There are two other commands that affect the behavior of
REPEAT loops: T NEXT and QUIT. See
the
NEXT (page ) and 140 QUIT (page ) commands for more information. 186