The following code doesn't compile saying the code is unreachable-
But following code (from K and B , page 343) does compile, even though the line - ' System.out.println("outer");' is never going to print , then why doesn't compiler treats it as unrechable code? :roll:
I am confused. Please somebody give me tips on how to determine if a given line of code is unreachable and when will the program fail to compile?
I am planning to give my scjp exam on thursday! [ January 07, 2008: Message edited by: prajal Mehta ]
Joined: Jul 24, 2007
Some situations where in unreachable statement error is thrown are statements after continue,break,return,if the condition is set to false etc....
their are some other cases. In your example when control reaches continue control has to be moved to label outer and hence for any value of i,j the statement System.out.println("Outer"); is not executed hence unreachable statement error is thrown.