Wheel IDE

Online demo »

Loops

For..to, step

With the to command, the counter is increased while the counter value is less or equal than the to value.

number i

for i = 1 to 10
    ; This code block will be executed 10 times...
end

When the step values is added then the counter will be increased with the step value:

number i

for i = 1 to 10 step 2
    ; This code block will be executed 5 times...
end

For..downto, step

With the downto command, the counter is decreased while the counter value is greater or equal than the downto value.

number i

for i = 7 downto 2
    ; This code block will be executed 6 times...
end

The downto loop can also have a step value:

number i

for i = 9 downto 0 step 3
    ; This code block will be executed 4 times...
end

Repeat

Repeat a block of code endless.

repeat
    ; This code block will be repeated endless
end

While

Repeat a block of code while a condition evaluates as true.

number n = 10

while n != 0
    n -= 1
end

Break

With the break command you can jump out of the inner most loop. You can use the break statement in combination with for, repeat and while loops.

number n = 0

repeat
    n++
    if n == 5
        break
    end
end

A break command can also refer to a specific loop. The code will continue after the end statement which belongs to the repeat statement.

number n = 0

repeat main_loop
    n++
    repeat
        n++
        if n == 10
            break main_loop
        end
    repeat
end
See also: syntax(Syntax)