|Repeat Until ()|
repeat until <>
The Repeat Until () block is a Control block and a C block. Blocks held inside this block will loop until the specified boolean statement is true, in which case the code beneath the block (if any) will execute. This loop is in similar nature to a
while loop in some other programming languages.
As this block loops pieces of code until a condition is true, the block is the best way to run code until a desired condition has been reached. Some common uses:
- Moving a sprite until its X or Y position is at a certain amount
repeat until <(x position) = > move (10) steps
- Having a sprite stick to the mouse until the mouse is not down
repeat until <not <mouse down?>> go to (mouse pointer v)
- Waiting for an event while performing an action
repeat until <. . .::grey> . . .
reset timer repeat until <(timer) > (limit)> . . . end
- Repeating a question until the user answers correctly
repeat until <(answer) = (correct answer)> ask [question] and wait end
After each iteration of the loop, a 1/30 of a second, or one frame, delay is added before the next iteration continues. This allows for animations to be run more smoothly. However, if you don't want this delay, turn on turbo mode, or put it inside of a custom block set to run without screen refresh. However, you must be certain that it will stop at some point, as otherwise, there can be signifigant issues with performance.
|Warning:||Putting a loop that never ends inside of a custom block set to run without screen refresh will cause the project to lag tremendously.|
- Main article: List of Block Workarounds
This block can be worked around with the following code:
define repeat until forever if <. . .::grey> then stop [this script v] end . . .
You can also make sure the script inside runs at least once, similar to do while loops in some programming languages:
define at least once: repeat until forever . . . if <. . .::grey> then stop [this script v] end