This article mainly introduces the Repeat...until Loop statement Usage Tutorial in Lua, is a basic tutorial in Lua's introductory learning, and needs friends to refer to the following
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:
The code is 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:
The code is 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:
The code is 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