local a, b, c = 3, 5, 7
local notes = {}
if c >= a and c >= b then
notes[#notes + 1] = "nothing is larger than c"
end
-- not 作用于括号 ( ) 中的整个条件
if not (a >= b or a >= c) then
notes[#notes + 1] = "a is the smallest"
end
-- 两个值不同时 ~= 为真
if a ~= b and b ~= c then
notes[#notes + 1] = "all three differ"
end
-- 不支持链式比较:两部分都要写出来
if a < b and b < c then
notes[#notes + 1] = "b is between a and c"
end
for _, note in ipairs(notes) do
print(note)
end
-- 陷阱:a < b < c 就是 (a < b) < c
local ok, err = pcall(function()
return a < b < c
end)
-- ok = false
-- err = main.lua:29: attempt to compare
-- boolean with number
print("ok = " .. tostring(ok))
print("err = " .. err)