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 九子订婚祝福语简短