A while loop statement in the LUA programming language that repeats the target statement whenever a given condition is true.
Grammar
The syntax for a while loop in the LUA programming language is:
Copy Code code as follows:
while (condition)
Todo
Statement (s)
End
Here, the declaration (S) can be a single statement or block of statements. The condition can be any expression, and it is really any value that is not 0. Loop iterations when the condition is true.
When the condition is false, the program control enters the row immediately after the loop.
Flowchart:
Here, the key point in the while loop is that the loop may not run forever. When the condition test results are false, the loop body is skipped, and the first statement after the loop is executed.
For example:
Copy Code code as follows:
a=10
while (a < 20)
Todo
Print ("Value of A:", a)
A = A+1
End
When the above code is compiled 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
Value of A:16
Value of A:17
Value of A:18
Value of a:19