*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unreachable stmts 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 stmts" Watch "Unreachable stmts" New topic
Author

Unreachable stmts

Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
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 ]
prashanth kumar
Ranch Hand

Joined: Mar 22, 2004
Posts: 162
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


SCJP1.5(86%)<br />SCWCD1.4(95%)<br />SCBCD1.3(92%)<br />IBM 252
Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
Hi,
This is tthe code
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18486
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unreachable stmts
 
Similar Threads
Assertion
Assertions
Help with loops
Valentin's mock exam no1
Unreachable statement