Lua repeat...until Loop
The repeat...until loop in the Lua programming language is different from for and while loops. The condition for for and while loops is evaluated at the beginning of the current loop, whereas the condition for the repeat...until loop is evaluated at the end of the current loop.
Syntax
The syntax for the repeat...until loop in the Lua programming language is:
repeat
statements
until( condition )
We notice that the loop condition (condition) is at the end of the loop body, so the loop body will execute at least once before the condition is evaluated.
The flowchart for the Lua repeat...until loop is as follows:
Example
--[ Variable definition --]
a = 10
--[ Execute loop --]
repeat
print("Value of a:", a)
a = a + 1
until( a > 15 )
Executing the above code will produce the following output:
Value of a: 10
Value of a: 11
Value of a: 12
Value of a: 13
Value of a: 14
Value of a: 15