Lua break statement
Lua programming language statements into the break loop, to exit the current loop or statement and begin execution of the script followed by the statement.
If you use nested loop, break statement to stop the execution of the innermost loop and begin execution of the outer loop.
grammar
Lua programming language break statement syntax:
break
flow chart:
Examples
The following examples of execution while loop, less than 20 output a value in a variable, and a greater than 15 terminates execution cycle:
--[ 定义变量 --] a = 10 --[ while 循环 --] while( a < 20 ) do print("a 的值为:", a) a=a+1 if( a > 15) then --[ 使用 break 语句终止循环 --] break end end
The above code is executed as follows:
a 的值为: 10 a 的值为: 11 a 的值为: 12 a 的值为: 13 a 的值为: 14 a 的值为: 15