如果标题没有多大意义,请原谅我.我不得不选择Is Lua的比较方式有用吗?和Lua的比较.
我今天想做这样的事情:
if currChar == nextChar == "-" then ... end
但它false
每次都会回来:
> currChar="-" > nextChar="-" > =currChar == nextChar == "-" false > -- All true in Python print(5 == 5) -- true print(5 == 5 == 5) -- false print((5 == 5) == (5 == 5)) -- true print(5 == (4 + 1) == (6 - 1)) -- false
我在一段时间内摆弄了这些值,并发现由于某种原因,Lua从左到右成对地比较值:
> = 52 > 3 > 2 stdin:1: attempt to compare number with boolean stack traceback: stdin:1: in main chunk [C]: in ? >
我有一种情况,这种形式的比较是有用的吗?
为什么比较那样?