aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes unreachable statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "unreachable statement" Watch "unreachable statement" New topic
Author

unreachable statement

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi

why the compiler thrown unreachable error

how the true or false in while loop influence the unreachable statement at (1) and (2)


class Test
{

public static void main (String args[])
{
int i=1;
do

while(false) //always true
System.out.println( "Ok" ) ;//unreachable statement (1)
while( i < 1 );

System.out.println("hai");
}
}



class Test
{

public static void main (String args[])
{
int i=1;
do

while(true) // true
System.out.println( "Ok" ) ;
while( i < 1 );

System.out.println("hai");//unreachable statement (2)
}
}
Anuj Troy
Ranch Hand

Joined: Apr 07, 2005
Posts: 30
hi Parameswaran

the statement System.out.println("hai");//unreachable statement (2) is unreachable because the while loop is infinite.
you have written while(true)!! it will never get out of that loop..

thus the last line

"System.out.println("hai");//unreachable statement (2)"

is unreachable.

regards
anuj


SCJP 1.4, SCWCD 1.4
your eyes cannot see what your mind does not know
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unreachable statement