This article mainly introduces the use of break statements in Lua, which is the basic knowledge of LUA's introductory learning, and needs friends to refer to the following
When a break statement is encountered in a loop, the loop terminates immediately, and the program control continues after the next loop statement.
If you are using a nested loop (that is, another loop inside a loop), the break statement stops the execution of the innermost loop and begins the following segment of the next line of code that executes.
Grammar
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)
Todo
Print ("Value of A:", a)
A=a+1
if (a > 15)
Then
--[terminate the loop using break statement--]
Break
End
End
When the above code is built and run, it produces 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