麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > 綜合 > 正文

詳解Lua中if ... else語句的使用方法

2024-07-21 23:04:51
字體:
供稿:網(wǎng)友

 if 語句后面可以跟一個可選的else語句,當布爾表達式為假該語句執(zhí)行。
語法

在Lua編程語言中的if ... else語句的語法是:

 

復制代碼 代碼如下:
if(boolean_expression)
then
   --[ statement(s) will execute if the boolean expression is true --]
else
   --[ statement(s) will execute if the boolean expression is false --]
end

 

如果布爾表達式的值為true,那么if代碼塊將被執(zhí)行,否則else代碼塊將被執(zhí)行。

Lua程序設計語言假定布爾true和非零值的任意組合作為true,以及它是否是布爾假或零,則假定為false值。但應當注意的是,在Lua零值被視為true。
 例如:

 

復制代碼 代碼如下:
--[ local variable definition --]
a = 100;
--[ check the boolean condition --]
if( a < 20 )
then
   --[ if condition is true then print the following --]
   print("a is less than 20" )
else
   --[ if condition is false then print the following --]
   print("a is not less than 20" )
end
print("value of a is :", a)

 

當建立和運行上面的代碼,它會產(chǎn)生以下結(jié)果。

 

復制代碼 代碼如下:
a is not less than 20
value of a is : 100

 

if...else if...else 語句

if語句后面可以跟一個可選的else if ... else語句,這是非常有用的使用,以測試各種條件單個if...else if 語句。

當使用if , else if , else語句有幾點要記住使用:

  •     if 可以有零或一個 else ,但必須在elseif之前。
  •     if 之后可以有零到很多else if在else之前。
  •     一旦一個else if成功,其它的elseif將不會被測試。

語法

if...else if...else...else語句在Lua編程語言的語法是:

 

復制代碼 代碼如下:
if(boolean_expression 1)
then
   --[ Executes when the boolean expression 1 is true --]

 

else if( boolean_expression 2)
   --[ Executes when the boolean expression 2 is true --]

else if( boolean_expression 3)
   --[ Executes when the boolean expression 3 is true --]
else
   --[ executes when the none of the above condition is true --]
end

 

例如:

 

復制代碼 代碼如下:
--[ local variable definition --]
a = 100

 

--[ check the boolean condition --]
if( a == 10 )
then
   --[ if condition is true then print the following --]
   print("Value of a is 10" )
elseif( a == 20 )
then  
   --[ if else if condition is true --]
   print("Value of a is 20" )
elseif( a == 30 )
then
   --[ if else if condition is true  --]
   print("Value of a is 30" )
else
   --[ if none of the conditions is true --]
   print("None of the values is matching" )
end
print("Exact value of a is: ", a )

 

當建立和運行上面的代碼,它會產(chǎn)生以下結(jié)果。

 

復制代碼 代碼如下:
None of the values is matching
Exact value of a is: 100
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 极品大长腿啪啪高潮露脸 | 一级黄色片武则天 | 把娇妻调教成暴露狂 | 久久久精品视频国产 | 婷婷久久影院 | 午夜在线视频一区二区三区 | av手机在线免费播放 | 欧美精品免费一区二区三区 | 一级黄色在线观看 | av成人在线电影 | 免费毛片在线视频 | 大奶一级片| 国产视频在线一区 | 成人在线视频黄色 | 国产视频精品在线 | 国产一区二区免费在线观看 | 国产五区 | 国产精品99久久久久久宅女 | 国产99一区二区 | 黄色视频a级毛片 | omofun 动漫在线观看 | 北原夏美av| 国产精品久久久久久婷婷天堂 | 成人18免费观看 | 国产精品白嫩白嫩大学美女 | 国产精品一区二区手机在线观看 | 久久人人爽人人爽人人片av免费 | 麻豆传传媒久久久爱 | 久久3| 久久精品亚洲欧美日韩精品中文字幕 | 国产一区二区三区影视 | 成人宗合网| 日韩黄在线 | 国产欧美一区二区三区免费看 | 国产伦久视频免费观看视频 | 欧美大电影免费观看 | 精品久久久久久久久久久aⅴ | 黄色视屏免费看 | 国产激爽大片在线播放 | 精品国产乱码久久久久久丨区2区 | 国内自拍网址 |