Why Java identifies unreachable code only in case of while loop? [duplicate]
问题 This question already has answers here : if(false) vs. while(false): unreachable code vs. dead code (2 answers) Closed 5 years ago . If I have code like public static void main(String args[]){ int x = 0; while (false) { x=3; } //will not compile } compiler will complaint that x=3 is unreachable code but if I have code like public static void main(String args[]){ int x = 0; if (false) { x=3; } for( int i = 0; i< 0; i++) x = 3; } then it compiles correctly though the code inside if statement