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 男朋友的祝福语简短
13 天仓节祝福语简短
14 立春幽默祝福语简短
15 新年祝福语鼠年简短创意
16 新年祝福语简短小猪
17 初三新年祝福语简短
18 新春祝福语大全 英语简短