REPEAT..UNTIL Loop
The while loop checks its condition before each iteration. If the condition is false from the start, the body never runs at all. Sometimes that’s not what you want — you need the body to execute at least once, and only then decide whether to keep going.
The repeat..until loop does exactly that. It runs the body first, then checks the condition. If the condition is true, the loop stops. If it’s false, the loop repeats.
Syntax
repeat <body>until <condition>Compare this with while:
| Checks condition | Guaranteed to run at least once? | |
|---|---|---|
while | Before each iteration | No |
repeat..until | After each iteration | Yes |
Example
Here is a simple repeat..until loop that waits for the player to press F5:
repeat wait 0until is_key_pressed 116The wait 0 always executes at least once, giving the game a chance to process input before the first check. Compare it with the equivalent while version:
while not is_key_pressed 116 wait 0endBoth achieve the same result, but notice how the condition is inverted: while needs not is_key_pressed (keep going while the key is not pressed), whereas repeat..until uses is_key_pressed directly (stop when the key is pressed).
Practical Example
This script counts how many seconds the player waits before pressing F5:
int seconds = 0
repeat wait 1000 seconds += 1 print_formatted_now "Waiting... %d seconds" 1000 secondsuntil is_key_pressed 116
print_formatted_now "You waited %d seconds!" 3000 secondsBecause repeat..until always runs the body first, the counter starts at 1 even if the player presses F5 immediately.