Is that a valid expression? If so, can you rewrite it so that it makes more sense? For example, is it the same as (4 > y && y > 1)? How do you evaluate chained logical operators?
Is that a valid expression? If so, can you rewrite it so that it
Share
The statement
(4 > y > 1)is parsed as this:The comparison operators
<and>evaluate left-to-right.The
4 > yreturns either0or1depending on if it’s true or not.Then the result is compared to 1.
In this case, since
0or1is never more than1, the whole statement will always return false.There is one exception though:
If
yis a class and the>operator has been overloaded to do something unusual. Then anything goes.For example, this will fail to compile: