Flow > Loops


Definite Loops

Repeat

repeat int times

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...[INT]) {
  [ACTIONS]
}

Example

loop-count-example

Prints out [0 1 2 3 4].


Indefinite Loops

While Loop

while boolean

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 until boolean

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.

Branching

Exit Loop

exit loop

Stops the execution of a loop's code.

break;

Return to Start of Loop

return to start of loop

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].