Control structures
The control structures if, while, and repeat have the usual meaning and familiar syntax.
statement ::= while exp do block end
statement ::= repeat block until exp
statement ::= if exp then block
{elseif exp then block}
[else block]
end
Lua also has a for statement, in two flavors.
The condition expression of a control structure can return any value. Both false and null are considered false. All values different from null and false are considered true (in particular, the number 0 and the empty string are also true).
In the repeat–until loop, the inner block does not end at the until keyword, but only after the condition. So, the condition can refer to local variables declared inside the loop block.
statement ::= return [explist]
statement ::= break
A break ends the innermost enclosing loop.
The return and break statements can only be written as the last statement of
a block. If it is really necessary to return or break in the middle of a block, then
an explicit inner block can be used, as in the idioms do return end and do
break end, because now return and break are the last statements in their
(inner) blocks.