1.循環語句
1.1 while
--while 語句練習
m_table = {, , }
local i =
while m_table[i] do
print(m_table[i])
i = i +
end
運作結果
1
2
3
2.2 repeat
repeat 相當于其他語言的 do-while
--repeat 語句練習
local snum =
repeat
print(snum)
snum = snum +
until snum ==
運作結果
1
2
3
4
5
6
7
8
9
2.3 for 語句
--for 語句
-- 初始值,門檻值,步進值
for i=, , do
print(i)
end
運作結果
1
3
5
7
9
2.邏輯關系運算符
- and
--and 如果第一為真,則傳回第二個數
print( and )
print( and )
-- 如果第一為假,則發你第一個數,lua隻有 false 和 nil 表示假
print(false and )
print(nil and )
運作結果
false
nil
- or
--or 如果第一為z真,則傳回第一個個數
print( or )
print( or )
-- 如果第一為假,則發你第二個數,lua隻有 false 和 nil 表示假
print(false or )
print(nil or )
運作結果
1
0
5
5
- not
--not
print(not false)
print(not nil)
print(not )
運作結果
true
true
false