File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unreachable statement

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic