Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unreachable statements

 
preeti khane
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
thanks
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find all rules for unreachable statements at JLS 14.20 Unreachable Statements
 
Jon Dornback
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic