Repeat until something changes
THE BASIC LANGUAGE
A WHILE loop checks before it starts. A DO loop with a test at the bottom always gets one turn. Choose the form that matches the rule you mean.
FUNCTION Run()
DIM turns = 0
WHILE turns < 2
turns += 1
WEND
DO
turns += 1
LOOP UNTIL turns >= 3
RETURN turns
END FUNCTIONThe WHILE runs at 0 and 1, stopping at 2. The DO body then adds one, and LOOP UNTIL tests the new value. The result is 3.
| WHILE … WEND | Use it when the body might need zero turns. |
|---|---|
| DO WHILE / DO UNTIL | Put the test at the top for another pre-tested form. Close with LOOP. |
| REPEAT … END REPEAT | Give a fixed number of repetitions. BREAK exits a loop. CONTINUE skips ahead to its next turn. |
Change the value your loop tests. A tight loop waiting for a person to click cannot process the click. Use a GUI event or WAIT UNTIL for something that can change on a later frame.
