This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the unreachable code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the unreachable code?" Watch "what is the unreachable code?" New topic

what is the unreachable code?

Simo Hayha

Joined: Jul 02, 2002
Posts: 19
what is the unreachable code?
i tried the following code:
if(false){int i=0;}
it is compiled successful
but when i tried the following code individually:
for(int i=0;false;i++){int j=0;}
while(false){int i=0;}
it can not be compiled!
so what's the unreachable code?
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
Please have a look at JLS 14.20 Unreachable Statements
In a nutshell, if(false) is tolerated to allow conditional compilation. for(;false ; ) and while(false) are not allowed by the compiler.
[ August 16, 2002: Message edited by: Valentin Crettaz ]

[Blog] [Blogroll] [My Reviews] My Linked In
It is sorta covered in the JavaRanch Style Guide.
subject: what is the unreachable code?
It's not a secret anymore!