概念
- Lua 編程語言流程控制語句通過程序設定一個或多個條件語句來設定凄贩。
在條件為 true 時執(zhí)行指定程序代碼誓军,在條件為 false 時執(zhí)行其他指定代碼。
if
用if(條件語句<真或假>) 執(zhí)行內(nèi)容 end
-
如果條件語句滿足昵时,則執(zhí)行內(nèi)容
if (true) then
print("do it !")
end
=>
do it !
if elseif 當a=1
local a = 1
if (a==1) then
print("a = 1")
elseif ( a == 2) then
print("a = 2")
end
=>
a = 1
if elseif 當a=2
local a = 2
if (a==1) then
print("a = 1")
elseif ( a == 2) then
print("a = 2")
end
=>
a = 2
if elseif else
local a = 3
if (a==1) then
print("a = 1")
elseif ( a == 2) then
print("a = 2")
else
print("else")
end
=>
else
<總結(jié)>
不管是if 還是elseif
- ==elseif 必須連寫==,不能像c#那樣分開
- if 或者 elseif 條件語句之后 ==必須加then==