91午夜福利一区,亚洲偷拍精品,蜜桃精品视频一区二区,日本一区二区草视频,精品无码久久久久久,91亚洲精品在线观看,性生活久久久,狠狠操中文字幕婷婷,久久大陆一区二区

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

時間:2020-08-28 19:31:04 句子

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

  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程序設(shè)計語言假定布爾true和非零值的任意組合作為true,以及它是否是布爾假或零,則假定為false值。但應(yīng)當注意的是,在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

【Lua中if ... else語句的詳解用法】相關(guān)文章:

《易經(jīng)》中的經(jīng)典語句06-21

《答謝中書書》作者詳解03-14

顧城作品中的經(jīng)典語句09-19

詩經(jīng)中的唯美語句04-24

詩經(jīng)中的優(yōu)美語句04-19

答謝中書書早晚美景的語句12-11

余光中散文精彩語句01-07

陸游的詩詞中的經(jīng)典語句03-11

觀滄海的意思詳解01-10

《觀潮》生字詳解11-14

临西县| 台中县| 沙河市| 洛宁县| 巴南区| 金阳县| 东光县| 桃园市| 阳春市| 廉江市| 福安市| 五华县| 临朐县| 磴口县| 洛南县| 高州市| 怀仁县| 玛纳斯县| 台南市| 拉萨市| 邛崃市| 津市市| 黎城县| 年辖:市辖区| 夏津县| 车险| 咸宁市| 宁武县| 临夏县| 阜南县| 秦安县| 南昌县| 阿克苏市| 台江县| 乌拉特后旗| 静乐县| 建阳市| 久治县| 玉龙| 中方县| 达日县|