Home > other >  Lua a strange problem mystery!
Lua a strange problem mystery!

Time:09-30

Today when I was at the lu lua found a strange problem

The local a=true
Print (a==true and false or true)

So whether a true or false, the output is true

I put the code into the
The local a=true
Print (not a)
It's good that

Haven't figured out why the first kind of ternary expression is no good?

CodePudding user response:

This is related to a operator precedence relations, I give you add parentheses you see (((a==true) and false) or true) that is equivalent to (or true), no matter what is a, this expression is return true

CodePudding user response:

https://blog.csdn.net/fightsyj/article/details/84559328

CodePudding user response:

The problem of operator precedence

CodePudding user response:

Or true

CodePudding user response:

Lua is not the ternary operator, by "and" and "or" is actually composed of pseudo three purpose, main is to use lua "and" and "or" characteristics, the building Lord indeed written expression is the return value is true,

CodePudding user response:

A and B or C: B not to false
https://blog.csdn.net/fightsyj/article/details/84559328

CodePudding user response:

This question actually have the answers online, is the problem of priority
https://blog.csdn.net/coffeecato/article/details/77546887

CodePudding user response:

Operator precedence

CodePudding user response:

The problem of priority,,,

CodePudding user response:

Want to add parentheses, habits or occasional problems often...
  • Related