aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 9243
    
    1

Hi Guys,

Consider the code below from Dan Chisholm,



How come it prints i1k1i2j1i3j2??


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
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
 
 
subject: Nested while loop??
 
Similar Threads
For loop question
Garbage collection question
loops
Help
loops