Why does a Java Compiler not produce an unreachable statement error for an unreachable then statement?
The behaviour is defined in the JLS description of unreachable statements: The then-statement is reachable iff the if-then statement is reachable. So the compiler determines that the then-statement (break;) is reachable, regardless of the condition in the if. And a bit further, emphasis mine: A basic for statement can complete normally iff at least one … Read more