jeudi 24 décembre 2015

Why does a Java Compiler NOT produce an UNREACHABLE STATEMENT error for an unreachable THEN statement?

If I try to compile

for(; ; )
{

}
System.out.println("End");

Java compiler produces an error saying Unreachable statement. But if I add another "unreachable"(according to me) break statement and make it:

for(; ; )
{
    if(false) break;
}
System.out.println("End");

It compiles. Why does it not produce an error? Is Java trying to say that Two wrongs do make a right?

EDIT : As per YoungHobbit's comment, even this produces an error:

for(; ; )
{
    if(false) continue;
}
System.out.println("End");

Aucun commentaire:

Enregistrer un commentaire