Flow > Loops


Definite Loops

Repeat

repeat-block

Repeats the wrapped blocks a given number of times. The embedded current loop count block returns how many times you've looped so far (starting from 0, ending at [NUMBER] - 1).

for(index0 in 0...[NUMBER]) {
  [ACTIONS]
}

Example

loop-count-example

Prints out [0 1 2 3 4].


Indefinite Loops

While Loop

while-block

Runs the wrapped blocks while the given condition is true. If the condition is false to begin with, nothing will run. Make sure that the condition becomes false at some point during the evaluation of the loop (or use the exit loop block), otherwise it will result in an infinite loop that will crash your game.

while([BOOLEAN]) {
  [ACTIONS]
}

Repeat Until Loop

repeat-block

Runs the wrapped blocks while the given condition is false. If the condition is true to begin with, nothing will run. Make sure that the condition becomes true at some point during the evaluation of the loop (or use the exit loop block), otherwise it will result in an infinite loop that will crash your game.

while(![BOOLEAN]) {
  [ACTIONS]
}

Example

repeat-example

This will calculate Fibonacci sequence numbers until the current number is greater than 10.

Loop Count Result Answer
Prev 1 -
Curr 1 -
1 1 + 1 2
2 1 + 2 3
3 2 + 3 5
4 3 + 5 8
5 5 + 8 13 <-- Greater than 10, stop looping.

Stopping

Exit Loop

exit-block

Stops the execution of a loop's code.

break;

Return to Start of Loop

return-block

Skips the rest of the code for an iteration of the loop and proceeds to the next iteration (if another iteration will be done).

continue;

Example

return-example

The loop prints out odd numbers between [0-9], so this will print out [1 3 5 7 9].


Stop

stop-block

Skips the rest of the code in this event for the current step/frame.

return;