这篇文章主要介绍了Lua中break语句的使用方法详解,是Lua入门学习中的基础知识,需要的朋友可以参考下wB4HTML5中文学习网 - HTML5先行者学习网
当循环中遇到break语句,循环立即终止,程序控制继续下一个循环语句后面。wB4HTML5中文学习网 - HTML5先行者学习网
如果您正在使用嵌套循环(即一个循环里面另一个循环),break 语句将停止最内层循环的执行并开始执行的下一行代码的程序后段。wB4HTML5中文学习网 - HTML5先行者学习网
语法wB4HTML5中文学习网 - HTML5先行者学习网
Lua break语句语法如下:wB4HTML5中文学习网 - HTML5先行者学习网
代码如下:wB4HTML5中文学习网 - HTML5先行者学习网
breakwB4HTML5中文学习网 - HTML5先行者学习网
例子:wB4HTML5中文学习网 - HTML5先行者学习网
代码如下:wB4HTML5中文学习网 - HTML5先行者学习网
--[ local variable definition --]wB4HTML5中文学习网 - HTML5先行者学习网
a = 10--[ while loop execution --]wB4HTML5中文学习网 - HTML5先行者学习网
while( a < 20 )wB4HTML5中文学习网 - HTML5先行者学习网
dowB4HTML5中文学习网 - HTML5先行者学习网
print("value of a:", a)wB4HTML5中文学习网 - HTML5先行者学习网
a=a+1wB4HTML5中文学习网 - HTML5先行者学习网
if( a > 15)wB4HTML5中文学习网 - HTML5先行者学习网
thenwB4HTML5中文学习网 - HTML5先行者学习网
--[ terminate the loop using break statement --]wB4HTML5中文学习网 - HTML5先行者学习网
breakwB4HTML5中文学习网 - HTML5先行者学习网
endwB4HTML5中文学习网 - HTML5先行者学习网
endwB4HTML5中文学习网 - HTML5先行者学习网
当建立和运行上面的代码,它会产生以下结果。wB4HTML5中文学习网 - HTML5先行者学习网
代码如下:wB4HTML5中文学习网 - HTML5先行者学习网
value of a: 10wB4HTML5中文学习网 - HTML5先行者学习网
value of a: 11wB4HTML5中文学习网 - HTML5先行者学习网
value of a: 12wB4HTML5中文学习网 - HTML5先行者学习网
value of a: 13wB4HTML5中文学习网 - HTML5先行者学习网
value of a: 14wB4HTML5中文学习网 - HTML5先行者学习网
value of a: 15wB4HTML5中文学习网 - HTML5先行者学习网