whileJavaで次の無限ループを見てください。その下のステートメントでコンパイル時エラーが発生します。
while(true) {
    System.out.println("inside while");
}
System.out.println("while terminated"); //Unreachable statement - compiler-error.
whileただし、次の同じ無限ループは正常に機能し、条件をブール変数に置き換えただけのエラーは発生しません。
boolean b=true;
while(b) {
    System.out.println("inside while");
}
System.out.println("while terminated"); //No error here.
2番目のケースでも、ブール変数bがtrueであるにもかかわらず、コンパイラーがまったく文句を言わないため、ループの後のステートメントは明らかに到達できません。どうして?
編集:次のバージョンはwhile明らかなように無限ループにif陥りますが、ループ内の条件が常にfalse、したがってループが戻ることはなく、コンパイラによって決定される場合でも、その下のステートメントに対してコンパイラエラーは発行されません。コンパイル時自体。
while(true) {
    if(false) {
        break;
    }
    System.out.println("inside while");
}
System.out.println("while terminated"); //No error here.
while(true) {
    if(false)  { //if true then also
        return;  //Replacing return with break fixes the following error.
    }
    System.out.println("inside while");
}
System.out.println("while terminated"); //Compiler-error - unreachable statement.
while(true) {
    if(true) {
        System.out.println("inside if");
        return;
    }
    System.out.println("inside while"); //No error here.
}
System.out.println("while terminated"); //Compiler-error - unreachable statement.
編集:とifと同じことwhile。
if(false) {
    System.out.println("inside if"); //No error here.
}
while(false) {
    System.out.println("inside while");
    // Compiler's complain - unreachable statement.
}
while(true) {
    if(true) {
        System.out.println("inside if");
        break;
    }
    System.out.println("inside while"); //No error here.
}      
次のバージョンのwhileも無限ループに陥ります。
while(true) {
    try {
        System.out.println("inside while");
        return;   //Replacing return with break makes no difference here.
    } finally {
        continue;
    }
}
これはfinally、returnステートメントがtryブロック自体の前にある場合でも、ブロックが常に実行されるためです。