This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

while vs. if

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
when i use while(false) in the code i got an error message saying
Unreachable code.But if i use if(false) i do not get an error.Why?
please explain.
Thanx.

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
while loop functions for (true) conditions. if u give false the rest of the code inside loop cant be reached
 
n.chenththuran
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this


while(true){
System.out.println("hi world");
}


a non ending loop
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was really implemented to allow the use of development-time checks that could be easily removed when a system went to production. For example, you could write code that looked like this:



When the system went to production, you could easily change the single line to set the variable IN_PRODUCTION to true and all of your development debugging code would automatically cease executing.

Obviously, you'd never use a while statement for this type of work, so it was only necessary to make if(false) compile - while(false) could still generate a compiler error.

Today, there is no need to do this. With Java 1.4, you have the capability to use assertions to do this exact type of thing for you.
 
Manish Agarwal
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for all for immediate reply.
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the explanation in the JLS ....After reading this question put up by Manish, I checked the JLS and found this out...as to why they have implemented it that way !!
Read the last part where you see the word 'HYPOTHETICAL' (Its a long document so you would have to scroll down quite a bit)

JLS
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic