unreachable statement in java??

Oct 07, 2009 14:49

As far as I know Javac or any other compiler never try to find program is in infinite loop or not. because one can not write a program to find a program is in infinite loop with complete accuracy.

Then how they identify unreachable statement? see the code below... both the code are in infinite loop

class foo
{
      public static void main(String[] args)
      {
              int i=0,j=0;
              while(true)
                 j=i;
        return;
      }
}

compiler says:
foo.java:8: unreachable statement
        return; 
        ^
1 error

class foo
{
      public static void main(String[] args)
      {
              int i=0,j=0;
              while(j==0)
                 j=i;
        return;
      }
}

compiler says: No error or warning

busy coding...

Previous post Next post
Up