国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > 綜合 > 正文

Lua中if語(yǔ)句嵌套的使用教程

2024-07-21 23:04:51
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

 在Lua編程內(nèi)嵌if-else語(yǔ)句,這意味著可以使用一個(gè) if 或 else if 在另一個(gè)語(yǔ)句if或else if 語(yǔ)句中。
語(yǔ)法

if語(yǔ)句的嵌套語(yǔ)法如下:

 

復(fù)制代碼 代碼如下:
if( boolean_expression 1)
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語(yǔ)句的方式。
例子:

 

復(fù)制代碼 代碼如下:
--[ local variable definition --]
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é)果。

 

復(fù)制代碼 代碼如下:
Value of a is 100 and b is 200
Exact value of a is : 100
Exact value of b is : 200
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 喀什市| 阿勒泰市| 双鸭山市| 得荣县| 山丹县| 娄底市| 太白县| 汉源县| 桐柏县| 阜新| 马尔康县| 临江市| 剑阁县| 高平市| 汝阳县| 来凤县| 涪陵区| 济阳县| 灌云县| 民县| 枞阳县| 铁岭市| 吉隆县| 抚松县| 正宁县| 汉中市| 孙吴县| 衡东县| 同心县| 乌海市| 余干县| 湘阴县| 永安市| 松溪县| 鄂伦春自治旗| 绥江县| 兴业县| 平顶山市| 绥滨县| 镇康县| 阿克陶县|