• 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: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Why 1& 4 are unreachable in the below code


Thanks,SCJP1.4


[HENRY: Added code tags. Fixed formatting.]
[ November 01, 2006: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you havent used "CODE" tag,your code is not properly formatted..

Now i can only see line 1 properly which is

while(false);

Here ";" is an empty statement and since false is hardcoded in while loop,";" never gets executed under any circumstances..And hence the compiler error

All The Best
 
Sireesha Mullapudi
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is tthe code
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
line 1: Even though the while loop only has an "empty" statement, this statement is still considered unreachable because the while loop can never be true.

line 4: Even though the for loop only has an "empty" statement, this statement is still considered unreachable because the for loop can never be true.

line 3: The check for a do loop executes at the end of the loop. This means that a do loop will execute at least once, regardless of whether it is true or false. The body is always reachable.

line 2: Technically this if statement's body is unreachable -- but this is allowed in the specifications. The reason that this is allowed is to provided for conditional code -- like debugging code.

Henry
 
Have you no shame? Have you no decency? Have you no tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic