Lua語言中的if-else控制結構很簡單明瞭。
local x=10
if x>=10 then
print('x>=10')
else
print('x<10')
end
local y=20
if y==20 then
print('y==20')
elseif y>20 then
print('y>=20')
else
print('y<20')
end
注意:
如果把elseif折開寫,則相當於是在else代碼塊中嵌套另一個if語句。
local z=10
if z==10 then
print('z==10')
else
if z>0 then
print('z>0')
end
end
閱讀更多 網絡圈 的文章