为什么这会起作用
local a, b =
true
and 1, 2
or 3, 4
print(a, b) --> 1 2但这不是?
local a, b =
false
and 1, 2
or 3, 4
print(a, b) --> false 2我怎么才能让它起作用?
发布于 2022-01-01 08:36:17
local a, b = true and 1, 2 or 3, 4等于
local a = 1 -- because true and 1 is 1
local b = 2 -- because 2 or 3 is 2进一步
local a, b = false and 1, 2 or 3, 4等于
local a = false -- because false and 1 is false
local b = 2 -- because 2 or 3 is 2在这里没有实际需要使用多个产品。所以简单地使用
local a = condition and 1 or 3
local b = condition and 2 or 4或
local a, b
if condition then
a, b = 1, 2
else
a, b = 3, 4
end此外,使用常量作为条件值也是没有意义的。它总是会产生同样的结果,所以为什么不立即使用这个结果呢?
https://stackoverflow.com/questions/70545748
复制相似问题