Akshay Rawal wrote:int x = 5;
while (false) { x=3; } //unreachable compiler gives error understood.
but in this case
it x =8;
for( int i = 0; i< 0; i++) x = 3; //no error how?? even it is unreachable
Compiler only operates at compile time -- so it can only determine the value of expressions using compile time constants.
It may be obvious to you that the body of the second loop is unreachable. However, to the compiler, using the rules of the current
Java Language Specification, it is not obvious. In fact, the compiler can't tell that the body of the loop is unreachable.
Henry