Detailed description of the use of the break statement in Lua
This article describes how to use the break statement in Lua. It is the basic knowledge of Lua. For more information, see
When a break statement is encountered in a loop, the loop is terminated immediately, and the program control continues after the next loop statement.
If you are using a nested loop (that is, another loop in one loop), the break statement stops the execution of the innermost loop and starts the execution of the next code line.
Syntax
The Lua break statement syntax is as follows:
The Code is as follows:
Break
Example:
The Code is as follows:
-- [Local variable definition --]
A = 10 -- [while loop execution --]
While (a <20)
Do
Print ("value of a:",)
A = a + 1
If (a> 15)
Then
-- [Terminate the loop using break statement --]
Break
End
End
When the above Code is created and run, 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