Until condition
Parameters
| condition - any expression; the loop stops when it becomes true (non-zero) |
Description
|
Closes a Repeat loop and keeps looping until its condition is true. Until reads the opposite way round to While: the loop carries on while the condition is false and stops the moment it turns true. Until KeyHit(1) means "go round again unless Escape was pressed". The test is at the bottom, so the body of a Repeat block always runs at least once, however the condition starts out. That is exactly what you want for a menu, a re-roll, or any "do it, then see if we are done" job. As everywhere else, the condition is just a number - zero is false, anything else true. And and Or join tests without short-circuiting, so both sides always run. If the loop should never end by itself, close it with Forever instead and leave with Exit. See also: Repeat, Forever, Exit, While, If. |
Example
; Until Example ; ------------- ; Vary the dice rolls on every run SeedRnd MilliSecs() turns=0 Repeat turns=turns+1 roll=Rand(1,6) Print "Turn "+turns+": you rolled a "+roll ; Until ends the loop once its condition becomes true - tested AFTER each pass Until roll=6 Print "" Print "A six! You escaped the dungeon after "+turns+" turns." Print "" Print "Press any key to close the example" WaitKey End
Index