Lua中if語句嵌套的使用教程
在Lua編程內(nèi)嵌if-else語句,這意味著可以使用一個(gè) if 或 else if 在另一個(gè)語句if或else if 語句中。
語法
if語句的嵌套語法如下:
then
--[ Executes when the boolean expression 1 is true --]
if(boolean_expression 2)
then
--[ Executes when the boolean expression 2 is true --]
end
end
您可以嵌套else if...else 以類似if語句的方式。
例子:
a = 100;
b = 200;
--[ check the boolean condition --]
if( a == 100 )
then
--[ if condition is true then check the following --]
if( b == 200 )
then
--[ if condition is true then print the following --]
print("Value of a is 100 and b is 200" );
end
end
print("Exact value of a is :", a );
print("Exact value of b is :", b );
當(dāng)建立和運(yùn)行上面的代碼,它會(huì)產(chǎn)生以下結(jié)果。
Exact value of a is : 100
Exact value of b is : 200
- JQuery自適應(yīng)IFrame高度(支持嵌套 兼容IE,ff,safafi,chrome)
- js實(shí)現(xiàn)網(wǎng)頁防止被iframe框架嵌套及幾種location.href的區(qū)別
- js中用window.open()打開多個(gè)窗口的name問題
- javascript window.open打開新窗口后無法再次打開該窗口問題的解決方法
- window.open()詳解及瀏覽器兼容性問題示例探討
- js中window.open打開一個(gè)新的頁面
- 講解Python中if語句的嵌套用法
- 詳解Java編程中if...else語句的嵌套寫法
- Window.Open打開窗體和if嵌套代碼
相關(guān)文章

Lua中實(shí)現(xiàn)php的strpos()以及strrpos()函數(shù)

Lua loadstring函數(shù)用法實(shí)例