Hi Karim,
You are correct that ++ and -- generally have higher precedence. If we
test a simple comparison condition, we see this clearly:
Output:
y :6
x :2
The increment operators were evaluated before the comparisons.
BUT the condition of an IF statement is evaluated left to right. So when we have a compound condition:
Output:
conditions met
x :4
y :4
To the left of the || operator, we see that the increment and decrement have been evaluated before the == test, as expected.
But think of the code to the right of the || operator as a self-contained statement whose evaluation happens totally independently.
This is why short-circuit operators are so useful. Not only is the result of the second comparison disregarded: it is never evaluated,
which means the second ++x is never reached.