*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unreachable code and compilation issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Unreachable code and compilation issues" Watch "Unreachable code and compilation issues" New topic
Author

Unreachable code and compilation issues

Andy James
Ranch Hand

Joined: Aug 22, 2005
Posts: 90
Hi all,

Why the following code doesn't compile?



whereas the following compiles successfully?



In both the cases, code int a = 10; will never execute, that is, is unreachable. Then why compilation is unsuccessful only for the while statement?

cheers
A
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

false condition has any sense for while loop ? Nope.It executes only when it is true.

Although false condition for if-else statement can have else part.



OCA7
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4341
    
    7

The Java Language Specification makes a specific exception for if statements. If you look at the relevant section, and read the example at the bottom, it explains why - basically it's there to enable conditional compilation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unreachable code and compilation issues
 
Similar Threads
Unreachable Code
Switch case doubt
what is the unreachable code?
What is this unreachable error
unreachable code