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 好听的元旦简短祝福语