YouTip LogoYouTip

Lua Repeat Until Loop

# Lua repeat...until Loop [![Image 4: Lua Loops](#) Lua Loops](#) In the Lua programming language, the `repeat...until` loop statement is different from `for` and `while` loops. The condition statement for `for` and `while` loops is evaluated at the beginning of the current loop iteration, while the condition statement for the `repeat...until` loop is evaluated at the end of the current loop iteration. ### Syntax The syntax for the `repeat...until` loop in the Lua programming language is: repeat statements until( condition ) We notice that the loop condition statement (`condition`) is at the end of the loop body, so the loop body will always execute once before the condition is evaluated. If the condition statement (`condition`) evaluates to `false`, the loop will start executing again. It will only stop executing when the condition statement (`condition`) evaluates to `true`. The flowchart for the Lua `repeat...until` loop is as follows: ![Image 5: Lua repeat...until Loop](#) ### Example ## Example -- a =10 -- repeat print("avalue is:", a) a = a +1 until( a >15) Executing the above code, the program output will be: avalue is:10 avalue is:11 avalue is:12 avalue is:13 avalue is:14 avalue is:15 [![Image 6: Lua Loops](#) Lua Loops](#)
← Unary Operators OverloadingProp Element Classlist β†’