if 语句后面可以跟一个可选的else语句,当布尔表达式为假该语句执行。
语法
在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代码块将被执行,否则else代码块将被执行。
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)
当建立和运行上面的代码,它会产生以下结果。
复制代码 代码如下: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 )
当建立和运行上面的代码,它会产生以下结果。
复制代码 代码如下:None of the values is matching
Exact value of a is: 100
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 刘德华.1989-永远...记得你(2012金碟复刻版)【EMI百代】【WAV+CUE】
- 《维纳斯璀璨假期死或生Xtreme》游戏特色玩法
- 《完蛋我被美女包围了前传》角色介绍
- 2024年免费游戏加速器推荐,稳定才是王道!
- 《蛋仔派对》小海鹦兰兰皮肤图鉴
- 《蛋仔派对》憨憨小六皮肤图鉴
- 《蛋仔派对》打工小电视皮肤图鉴
- 叶启田2006-人生[台湾首版][WAV+CUE]
- [雨果唱片]陈百强2012《同名专辑LPCD45》[WAV+CUE]
- 安七炫2005-面具(中文版)[SM娱乐][WAV+CUE]
- 曝AMD曾有机会为Switch2提供芯片 却因能耗错失机会
- 《塞尔达传说:智慧的再现》新作上市宣传片公开 M站86分
- 宫本茂谈AI技术应用:任天堂更愿意走不同的路
- 《蔡琴 不了情 经典歌曲香港演唱会2CD》[ISO][6.6GB]
- 《萧煌奇 说故事的歌 2022》[FLAC/分轨][380MB]