lua 条件控制

时间:2023-03-08 21:55:23
lua 条件控制

lua 条件控制

if 语句

结构

if (condition)
then
statements
end

示例程序

local a = 10

if (a > 1)
then
print("if condition")
end

if … else … 语句

结构

if (condition)
then
statements
else
statements
end

示例程序

local a = -1

if (a > 10)
then
print("if condition")
else
print("else condition")
end

if … elseif … 语句

结构

if (condition)
then
statements
elseif (condition)
then
statements
else
statements
end

示例程序

local a = 10

if (a > 20)
then
print("if condition")
elseif (a > 1)
then
print("elseif condition")
else
print("else condition")
end