Unlike for and while loops, the loop condition is tested at the top of the loop, and the Repeat...until loop of the LUA programming language checks the state at the bottom of the loop.
The Repeat...until loop is similar to a while loop, which is different from do ... while loops are guaranteed to execute at least once.
Grammar
The syntax for the LUA programming language Repeat...until loops is:
Copy Code code as follows:
Repeat
Statement (s)
Until (condition)
Note that the conditional expression appears at the end of the loop, so you test the condition before the Loop statement (S) executes once.
If the condition is false, the control process jump backup execution Loop statement (S) executes again. This process is repeated until the given condition becomes true.
Flow chart:
For example:
Copy Code code as follows:
--[local variable definition--]
A = 10
--[repeat loop Execution--]
Repeat
Print ("Value of A:", a)
A = a + 1
Until (a > 15)
When the above procedure is established and executed, it produces the following results:
Copy Code code as follows:
Value of A:10
Value of A:11
Value of A:12
Value of A:13
Value of A:14
Value of A:15