lua邏輯運算子
- and or not
--and 與 or
--返回的不是true 和 false
--而是它的兩個運算元
--[[
a and b a為false 返回a
a or b a為true 返回a
]]print( 4 and 5) --> 5
print( nil and 13) --> nil
print( false and 13) -->false
print( 4 or 5) -->4
print(false or 5) -->5
乙個很實用的技巧:如果 x 為 false 或者 nil 則給 x 賦初始值 5
x = x or 5
--[[等價於
if not x then
x = 5
end]]
三元運算子在lua中得實現
--a?b:c 用and 和 or表示
print(false and 3 or 4)
not 的結果一直返回 false 或者 true
print(not nil) -->true
print(not false) -->true
print(not 0) -->false 0也是true
print(not not nil) -->false
lua 邏輯運算子小結
lua中的邏輯運算子,認為只有false nil為假,其他的都為真 包括0 空串 a and b 如果a為false,則返回a,否則返回b a or b 如果a為true,則返回a,否則返回b 1 print 4 and5 52 print nil and12 nil3 print false an...
mysql 動態邏輯運算 MySQL 邏輯運算子
not 10 10 not 1 1 1 1 not 1 1 not null 0 0 1 1 0 null 2 邏輯與 and 或 1 當所有運算元均為非零值 並且不為 null 時,所得值為 1 2 當乙個或多個運算元為 0 時,所得值為 0 3 其餘情況所得值為 null mysql selec...
邏輯運算 位運算
今天有人問我,邏輯運算是什麼,現在來解釋一下 邏輯運算就是相當於資訊競賽基礎工具中的一位的位運算 符號對應關係 wedge cap 交 and 與運算 vee cup 並 or 或運算 neg not 非 xor 異或運算 x k 將x的二進位制右移k位 如 x 10110 2 時,k 1,那麼x ...