While loking up "dead code" thread here dead code warning in eclipse
I tried the following simple java code:
public class Test2
{
public static void main(String[] args)
{
int x = 0;
while(false)
{
x=4;
}
}
}
which correctly throws a compile time error
C:\Documents and Settings\user\Desktop\Test2.java:7: unreachable
statement
{
^ 1 error
I tweaked the code very slightly to this:
public class Test2
{
public static void main(String[] args)
{
int x =0;
while(true)
{
x=4;
}
}
}
and it compiles just fine.
Is there a reason, why this compiles fine?
logically both should cause an infiniteloop and should both cause compile time error.
Am I doing something wrong?