Why does (i<=j && j<=i && i!=j) evaluate to TRUE?
i <= j
is evaluated totrue
, because auto unboxing happens for int comparisons and then bothi
andj
hold the default value,0
.j <= i
is evaluated totrue
because of the above reason.i != j
is evaluated totrue
, because bothi
andj
are different objects. And while comparing objects, there isn't any need of auto unboxing.
All the conditions are true, and you are not changing i
and j
in loop, so it is running infinitely.
Because you are comparing
0 < = 0 (true) // unboxing
0 > = 0 (true) // unboxing
reference != secondReference (true)
as you are creating objects, not a primitive comparison. So it evaluates towhile(true) { // Never ending loop }
.