97骚碰,毛片大片免费看,亚洲第一天堂,99re思思,色好看在线视频播放,久久成人免费大片,国产又爽又色在线观看

Lua中if ... else語(yǔ)句的詳解用法

時(shí)間:2020-08-28 19:31:04 句子 我要投稿

Lua中if ... else語(yǔ)句的詳解用法

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

  語(yǔ)法

  在Lua編程語(yǔ)言中的.if ... else語(yǔ)句的語(yǔ)法是:

  代碼如下:

  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代碼塊將被執行,否則else代碼塊將被執行。

  Lua程序設計語(yǔ)言假定布爾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)

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

  代碼如下:

  a is not less than 20

  value of a is : 100

  if...else if...else 語(yǔ)句

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

  當使用if , else if , else語(yǔ)句有幾點(diǎn)要記住使用:

  if 可以有零或一個(gè) else ,但必須在elseif之前。

  if 之后可以有零到很多else if在else之前。

  一旦一個(gè)else if成功,其它的elseif將不會(huì )被測試。

  語(yǔ)法

  if...else if...else...else語(yǔ)句在Lua編程語(yǔ)言的語(yǔ)法是:

  代碼如下:

  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 )

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

  代碼如下:

  None of the values is matching

  Exact value of a is: 100

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

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

《答謝中書(shū)書(shū)》作者詳解03-14

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

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

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

答謝中書(shū)書(shū)早晚美景的語(yǔ)句12-11

余光中散文精彩語(yǔ)句01-07

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

觀(guān)滄海的意思詳解01-10

《觀(guān)潮》生字詳解11-14

屯门区| 通山县| 维西| 永川市| 保靖县| 华坪县| 西充县| 麦盖提县| 台中县| 平陆县| 夹江县| 合作市| 红桥区| 南宫市| 满洲里市| 滕州市| 什邡市| 镇赉县| 汾西县| 嫩江县| 蚌埠市| 元朗区| 名山县| 勃利县| 许昌市| 会泽县| 常德市| 石嘴山市| 东至县| 巨野县| 高尔夫| 朝阳区| 集安市| 武安市| 宾川县| 太湖县| 微博| 宜兰县| 定陶县| 博客| 正阳县|