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  do while loop 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 " do while loop" Watch " do while loop" New topic

do while loop

M Srilatha
Ranch Hand

Joined: Aug 27, 2008
Posts: 137

Could any one please explain me how the following code works?

I thought the code will not compile! But it compiles as well as runs

Thanks,<br />Srilatha M
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

why you thought that this code will not compile? it looks OK. no problem in the code.

My Blog SCJP 5 SCWCD 5
M Srilatha
Ranch Hand

Joined: Aug 27, 2008
Posts: 137
Hey thanks for the reply!

I got it now.
This is how it works!

Before i was thinking that line 4 is a do while loop where its actually do in line4 pairs up with while in line 06. I didnt think in that way.

Anyways now its clear!
Ankit Garg

Joined: Aug 03, 2008
Posts: 9462

I think there will be no output.

The code can be thought of as

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: do while loop
It's not a secret anymore!