Skip to content
Saule
Docs

Loops

for i: integer = 1, 10 do
print(i)
end
-- with step
for i: integer = 0, 100, 5 do
print(i)
end
-- counting down
for i: integer = 10, 1, -1 do
print(i)
end
local names: table<string> = {"Arthur", "Merlin", "Lancelot"}
for name: string in names do
print(name)
end
-- with index
for i: integer, name: string in names do
print(i .. ": " .. name)
end
-- types are optional — inferred from the iterated value
for name in names do
print(name)
end
local hp: integer = 100
while hp > 0 do
hp = hp - 10
end

Runs at least once, checks the condition at the end:

local tries: integer = 0
fn getInput() -> string?
tries = tries + 1
if tries < 3 then
return nil
end
return "ready"
end
local input: string? = nil
repeat
input = getInput()
until input != nil
println(input ?? "") -- ready
println(tries) -- 3, the body always ran at least once
for i: integer = 1, 10 do
if i == 5 then continue end
if i == 8 then break end
print(i) -- prints 1, 2, 3, 4, 6, 7
end