我不明白的LUA邏輯運算符/ A B:C運營商
aBoolValue = false
ans = aBoolValue and 'yes' or 'no'
print (ans)
什麼是「和」和「或」操作正是工作的邏輯是什麼?
我不明白的LUA邏輯運算符/ A B:C運營商
aBoolValue = false
ans = aBoolValue and 'yes' or 'no'
print (ans)
什麼是「和」和「或」操作正是工作的邏輯是什麼?
我倒是投票下來這是一個唯一的鏈接的答案,但「文檔是你的朋友」始終是一個很好的答案。 – 2014-09-24 23:23:18
@Tom Blodget「lua and or」幾乎立即引導到該頁面,我很確定這個問題應該是downvoted,而不是一個答案。 – user3125367 2014-09-25 16:29:35
考慮以下代碼:
local example1 = true and "yes" or "no"
local example2 = false and "yes" or "no"
print(example1, example2) --> yes no
如果布爾值爲true,之後的值將被返回。如果布爾值爲false,則返回後面的值。想想看這樣的:
local example1 = if (true) then "yes" else "no"
--obviously this code won't work, but it shows how ternary operations work
查找Lua的短路評價 – 2014-09-24 07:19:48