This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Nested while loop?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Nested while loop??" Watch "Nested while loop??" New topic
Author

Nested while loop??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Hi Guys,

Consider the code below from Dan Chisholm,



How come it prints i1k1i2j1i3j2??


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

the first while is not the while of the do loop. The while of a do loop is always followed by a semikolon.

The first while plus the following output line really is the statement, that is executed in the do loop.

The second while, followed by a semikolon marks the end of this do while loop. The second while is not an independent while loop with only a ; to execute.


With brackets and better indentation the code looks like


You should now see, why the output is i1k1i2j1i3j2.



Yours,
Bu.


all events occur in real time
 
jQuery in Action, 2nd edition
 
subject: Nested while loop??
 
Similar Threads
loops
For loop question
Garbage collection question
loops
Help