0

Can I use if(1 <= x <= 2) instead of if(1 <= x && x <= 2)

It looks like not working if I combine them together, but basically they mean same. I am a bit confused.

  • 1
    `1 <= x <= 2` is `(1 <= x) <= 2` which evaluates the first comparison then checks if the boolean result from it is less or equal to two. And all booleans would be less or equal to two since `false` converts to zero and `true` converts to one. So you *can* use that one condition instead of two. It just doesn't do the same thing. – VLAZ Nov 08 '22 at 07:03

0 Answers0