Latest web development tutorials

Lua cycle

In many cases we need to do some regular repeat the operation, so the program will need to repeat certain statements.

A set of statements to be executed repeatedly called loop, can continue to repeat, we decided to terminate the loop condition.

Loop structure is the repetition structure of certain procedures in the process under certain conditions, the program is executed is referred to repeatedly loop.

Loop by loop and loop termination condition of two parts.

Lua language provides the following treatment cycle:

Type of cycle description
while loop When the condition is true, let the program repeatedly executes certain statements. We will check whether the conditions before executing the statement is true.
for loop Repeat the statement specified number of repetitions can be controlled for statement.
Lua repeat ... until Repeat the cycle until a specified condition is true so far
Nested loop One or more can be nested loop inside the loop (while, for, do..while)

Loop control statements

Loop control statement to control program flow, in order to achieve a variety of ways the structure of the program.

Lua supports the following loop control statements:

Control statements description
break statement Exit the current loop or statement and begin execution of the script followed by the statement.

Infinite loop

In the body of the loop if the condition is always true the loop will always execute it, to the following while loop example:

while( true )