Possible Duplicate:
Why is this code giving an “Unreachable Statement” error?
This seems very easy question, I found this question in one book. If anyone help me to figure out why I'm getting error.
do {
System.out.print("inside do");
} while (false);
while (false) { // error
System.out.print("inside while");
}
System.out.print("outside");
I thought, and according to me, output should be inside dooutside. But, it is showing Compiler Error : Unreachable Statement. Then, I tried to figure out, why, it is showing Compilation error : Unreachable Statement* . So, I change the above code like this
boolean i = false;
do {
System.out.print("inside do");
} while (false);
while (i) { // ok
System.out.print("inside while");
}
System.out.print("outside");
Now, it is showing expected output i.e. inside dooutside . So, my question is - what makes difference in first and second case ? Also, when I check
if(false){
//something here
}
Then, above code executes without any error.