Skip to content

for (C-style)

Control flow

C for. Emits while plus a trailing increment. Semicolons separate clauses.

for (int i = 0; i < n; i++) {
}
NameTypeDescription
initstmtRuns once.
condboolChecked every iteration.
stepexprUsually i++.

None.

local i = 0 / while i < n do / i += 1

Range-for is a different form: for (T name in collection). Do not mix it with the C-style semicolons.

for (int i = 0; i < 10; i++) {
post("Count: " .: i);
}

Emits:

local i = 0
while i < 10 do
print("Count: " .. i)
i += 1
end

range-for · while · operator-increment