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 教师闺蜜祝福语简短