English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The repeat...until loop statement in Lua programming language is different from the for and while loops. The condition statements of for and while loops are judged at the beginning of the current loop execution, while the condition statements of repeat...until loops are judged after the current loop execution.
The syntax format of repeat...until loop in Lua programming language:
repeat statements until(condition)
We notice that the loop condition judgment statement (condition) is at the end of the loop body, so the loop body will always be executed once before the condition is judged.
If the condition judgment statement (condition) is false, the loop will restart execution until the condition judgment statement (condition) is true, at which point the execution will stop.
The flow chart of Lua repeat...until loop is as follows:
--[ Variable Definition --] a = 10 --[ Execute Loop --] repeat print("The value of a is:", a) a = a + 1 until(a > 15 )
After executing the above code, the program outputs the following result:
The value of a is: 10 The value of a is: 11 The value of a is: 12 The value of a is: 13 The value of a is: 14 The value of a is: 15