The usage of the while LOOP statement in Lua
This article describes how to use the while LOOP statement in Lua. It is the basic knowledge in Lua beginners. For more information, see
The while LOOP statement in Lua programming language repeats the target statement if the given condition is true.
Syntax
The while LOOP syntax in Lua programming language is:
The Code is as follows:
While (condition)
Do
Statement (s)
End
Here, the declaration (S) can be a single statement or statement block. This condition can be any expression and is actually any non-zero value. Loop iteration when the condition is true.
If the condition is false, the program controls the line following the loop.
Flowchart:
Here, the key point in the while loop is that the loop may not run forever. When the condition test result is false, the loop body is skipped, and the first statement after the loop is executed.
For example:
The Code is as follows:
A = 10
While (a <20)
Do
Print ("value of a:",)
A = a + 1
End
When the above Code is compiled and executed, it will produce 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
Value of a: 16
Value of a: 17
Value of a: 18
Value of a: 19