About Question enthuware.ocajp.i.v7.2.849 :
Posted: Thu Jun 16, 2016 1:40 pm
Hello, having some problems with the "unreachable code" topic :
why isn“t the rest of the code unreachable, ending in a compilation fail ?:
In the 2nd iteration , when "b".equals(s) is true , the if executes "continue" , right? so it goes to the 3rd iteration, but...public class TestClass {
public static void main(String[] args) throws Exception {
String[] sa = {"a", "b", "c"};
for(String s :sa){
if("b".equals(s)) continue;
System.out.println(s);
if("b".equals(s)) break;
System.out.println(s+" again");
}
}
}
why isn“t the rest of the code unreachable, ending in a compilation fail ?:
System.out.println(s);
if("b".equals(s)) break;
System.out.println(s+" again");