This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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

Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 9280

I think there will be no output.

The code can be thought of as

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: do while loop
Similar Threads
Intra Ranch Go Game!
Bit-shift operators and primitive types
Replace text by HTML links
do...while() statement question
do while loop