Latest web development tutorials

Lua while loop

Lua cycle Lua cycle

Lua programming language while loop is determined that the condition is true will repeat the loop statement.

grammar

Lua programming language while loop syntax:

while(condition)
do
   statements
end

statements (loop statements) may be one or more statements, condition (condition) can be any expression, the loop body statement is true in the condition (condition).

Flow chart is as follows:

In the above flow chart, we can see the condition (condition) is false skips the current cycle and begin execution of the script followed by the statement.

Examples

The following examples of a cycle of the output values:

a=10
while( a < 20 )
do
   print("a 的值为:", a)
   a = a+1
end

Implementation of the above code, the output results are as follows:

a 的值为:	10
a 的值为:	11
a 的值为:	12
a 的值为:	13
a 的值为:	14
a 的值为:	15
a 的值为:	16
a 的值为:	17
a 的值为:	18
a 的值为:	19

Lua cycle Lua cycle