Lua中if语句嵌套的使用教程
在Lua编程内嵌if-else语句,这意味着可以使用一个if或elseif在另一个语句if或elseif语句中。
语法
if语句的嵌套语法如下:
if(boolean_expression1)
then
--[Executeswhenthebooleanexpression1istrue--]
if(boolean_expression2)
then
--[Executeswhenthebooleanexpression2istrue--]
end
end
您可以嵌套elseif...else以类似if语句的方式。
例子:
--[localvariabledefinition--] a=100; b=200;
--[checkthebooleancondition--] if(a==100) then --[ifconditionistruethencheckthefollowing--] if(b==200) then --[ifconditionistruethenprintthefollowing--] print("Valueofais100andbis200"); end end print("Exactvalueofais:",a); print("Exactvalueofbis:",b);
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短