Skip to content

Latest commit

 

History

History
89 lines (67 loc) · 709 Bytes

File metadata and controls

89 lines (67 loc) · 709 Bytes

1.5 流程控制

lua中false和nil均为false,true和非nil均为true

if

语法

if condition then
    statements
end

示例

a=20
if a>10 then
    print(a)
end
20
a<10

if else

语法

if condition then
    statements
else
    statements
end

示例

a=10
if a>9 then
    print("a > 9")
else
    print("a < 9")
end
a > 9

if elseif else

语法

if condition then
    statements
elseif condition then
    statements
else
    statements
end

示例

a=5
if a>5 then
    print("a>5")
elseif a>3 then
    print("a>3")
else 
    print("else statements")
end
a>3