Skip to content

Loops ​

There are two kinds of loop control statements:
conditional loops and counting loops (those that control how many times the body runs based on the values of variables)

Repeat ​

The simplest repeat block runs the code in its body a specified number of times.

controls_repeat

Python ​

python
for count in range(times):
    # ...

Count with ​

The count with block (commonly called a for loop) increases a variable from the from value to the to value by the by amount, running the body once for each value.

controls_for

Python ​

python
for VAR in range(from, to + 1, by):
    # ...

For each item ​

The for each item block is similar, except that it steps through the values in a list instead of a sequence of numbers.

controls_forEach

Python ​

python
for VAR in list:
    # ...

Repeat while / until ​

The repeat while block repeats the body as long as the condition is true.
The repeat until block repeats the body while the condition is false, and exits the loop as soon as the condition becomes true.

controls_while

Python ​

python
# unit = "while"
while condition:
    # ...

# unit = "until"
while not condition:
    # ...

Break / continue ​

The break block lets you exit a loop early.
The continue block skips the rest of the code in the body and starts the next iteration (pass).

controls_flow_statements

Python ​

python
break
continue