Skip to content

Loops

Boa supports two kinds of loops: the for loop and the while loop.

The for loop

Boa does not have a C-style for (initialisation; condition; incrementation) but a for loop based on ranges:

boa
for number in [1, 2, 3, 4, 5]:
    println(number)

// will print:
// 1
// 2
// 3
// 4
// 5

Use break to leave the loop as soon as it is encountered, and continue to directly jump to the next iteration.

The while loop

The while loop in Boa is similar to basically all the other existing while loops:

boa
while condition:
    ...

Use true as the condition to create an infinite loop:

boa
while true:
    ...

Like the for loop, it is possible to use break and continue inside a while loop.