在Lua編程內(nèi)嵌if-else語(yǔ)句,這意味著可以使用一個(gè) if 或 else if 在另一個(gè)語(yǔ)句if或else if 語(yǔ)句中。
語(yǔ)法
if語(yǔ)句的嵌套語(yǔ)法如下:
您可以嵌套else if...else 以類似if語(yǔ)句的方式。
例子:
--[ 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é)果。
新聞熱點(diǎn)
疑難解答
圖片精選