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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

about statement unreachable

 
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
public class ZZY {
static boolean condition = true;
public static void main ( String [ ] args) {
int i = 0 ;
if (false){ i++;}
while (condition) {
i++ ;
if (i>4) break ;
}
System.out.println(i) ;
}
}




When i change while (condition) to while(false) .... i get a compile time error of statement unreachable .... however even i++ is unreachable in if (false){ i++;} .. but it does not give a complite time error.

So can anyone tell me the situations in which we wouid get a compile time error of statement unreachable .

Thanks
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
If you set condition = false and pass condition to while() loop then it will compile fine.
 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
hi
can you tell me the differnce between while(false) and while (condition ) .. where condition has been set to false ??
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not post the same question twice.
Continue in your other post.
 
I am going to test your electrical conductivity with this tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
    Bookmark Topic Watch Topic
  • New Topic