Comparing three integer values
In some languages you can use that shorthand. For example in Python a == b == c
is roughly equivalent to the expression a == b and b == c
, except that b is only evaluated once.
However in Java and Javascript you can't use the short version - you have to write it as in the second example. The first example would be approximately equivalent to the following:
boolean temp = (a == b);
if (temp == c) {
// ...
}
This is not what you want. In Java a == b == c
won't even compile unless c
is a boolean.