File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes unreachable statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "unreachable statements" Watch "unreachable statements" New topic

unreachable statements

preeti khane
Ranch Hand

Joined: Mar 12, 2003
Posts: 93
Can someone tell me all the possible situations for unreachable statements
I know a few:
- while(false){ ....}
- a return when the try catch finally has return statements

- a statement after a break in an if enclosed in a loop
any other examples?
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
You can find all rules for unreachable statements at JLS 14.20 Unreachable Statements

[Blog] [Blogroll] [My Reviews] My Linked In
Jon Dornback
Ranch Hand

Joined: Apr 24, 2002
Posts: 137
an interesting side note (discovered by accident) is the empty statement (ie, a ";" on a line with nothing else). in java 1.3, a statement like break;; or return;; was accepted by the compiler, but if the same code is compiled under 1.4 it is a compiler error because the second ; is considered an unreachable statement. (not that it has any use, it was just a typo that raised a point about compiler differences).

use the [CODE] tags - it makes it much easier for people to help you.
I agree. Here's the link:
subject: unreachable statements
jQuery in Action, 3rd edition