Skip to main content

Loops

General

Loops are one of the most important control structures in programming. They help you whenever you want to repeat one or more instructions a certain number of times. In Blockly, there are different types of loops, but their functionalities are always very similar. You can find all loops in the corresponding category in the toolbox.

Repeat X Times Loop

The simplest loop is the Repeat X Times loop. In it, all commands within the loop are repeated X times.

Repeat While Loop

The second loop is the Repeat While/Until loop. The commands inserted in the loop are only executed if a condition attached to the free block section is met/true. In the block's dropdown menu, you can select whether the commands should be executed until a condition is met, or while a condition is met.

Loop with Counter Variable

The third loop is implemented using a counter variable, which can also be used within the program. First, a variable is initialized with a start value and a maximum value is set for it. Then, the counter variable is increased by the specified number after each iteration. This way, an instruction can be set for each state of the counter variable.