jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes loops 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 "loops" Watch "loops" New topic


boopathy Gopalsamy

Joined: Feb 07, 2005
Posts: 5
could any of u tell why this code doesn't produce an unreachable statement error.

code snippet:
for(;true ;
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Which statement do you think is unreachable?

Mike Gershman
SCJP 1.4, SCWCD in process
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214

I see a SMILEY face in the example code. So I am not sure what the syntax was supposed to look like...

Is this because the code is not added within CODE tags?



SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
Jeff Tian

Joined: Jan 06, 2005
Posts: 12
Any code that you have after that do while loop will be unreachable.

The magic of believing in yourself is to risk all that you have for a dream <br />that nobody sees but you. (Million Dollar Baby)<br /> <br />SCJP 1.4
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
You can check the "Disable smilies in this post" checkbox to make that kind of thing readable.

And use the pencil icon to go back and edit it.
[ March 29, 2005: Message edited by: Carol Enderlin ]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
If there are no statements after the while clause, there are no unreachable statements.
Jeff Jetton
Ranch Hand

Joined: Mar 29, 2005
Posts: 71

I've reposted what I think the original poster's code is.

So the "for" loop is infinite, right? So wouldn't the "while" clause itself be unreachable? Or does the compiler evaluate the "while" before it moves in to look at what inside the loop?

- Jeff
[ March 30, 2005: Message edited by: Jeff Jetton ]
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
The compiler just checks here if do statement is reachable or not, The do statement here meaning do-while. So u cant seperate out do and while, its the same.
I agree. Here's the link: http://aspose.com/file-tools
subject: loops
It's not a secret anymore!