1.格式:
if 条件 then
执行语句
elseif 条件 then
执行语句
【else】
【执行语句】
end
需要注意的点
①条件 不用括号()
②执行语句不用{} 而是使用then
③elseif 中间不加空格
在lua中没有switch语法,需要自己实现
条件是和条件运算符和逻辑运算符混合使用
print("条件分支语句的使用")
--单条件判断
a=9
if a<=9 then
print("a<=9")
end
--if else 使用
if a<=8 then
print("a<=8")
else
print("a>=8")
end
--if elseif else 使用
if a<=8 then
print("a<=9")
elseif a<=10 then
print("a<=10")
else
print("a>10")
end