• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unreachable statement

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
}
}
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic