The first loop is infinite loop. Since the condition is always true, and will always be satisfied.
It's like writing:
int i=0;
while(true)
i++;
As you can see, the condition is always true
and nothing changes this true.
The second loop is Unreachable code
since the piece of code below this loop will never be reached (false
is always false and you never change it). So it's redundant.
See Chapter 14.21. Unreachable Statements
Since Java
knows that the programmer is human :) it notifies you about this to prevent mistakes.
Note that while(false)
or the second loop you have differ from if(false)...
since while(false)
(or the loop you have) doesn't make sense because the code below it will no be execute. Not like if(false)
that might have else
, so the compiler doesn't complain about it in this case.
Regarding the OP update:
In the third case there will be no compilation error since the false
value is assigned to the variable and in this case, the variable can be re-assigned to have true
value in it. So the compiler doesn't arise an error.
Note that if the variable is declared as final
then the compiler will arise an error since this variable can be never assigned to a new value, thus the code below the for
loop will be unreachable.