• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Related to Looping..

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does this work... Plz explain...



i get the result as 121212
no way i am able to trace the flow... plz explain me abt this ...

[ADDED Code Tags to make code readable. Mark]
[ March 03, 2006: Message edited by: Mark Spritzler ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, you have your do-while loop that only checks after it runs the for loop.

(A) The for loop counts, since the post incrementer is on the boolean expression,
(B)the check is first i = 0 and it is less than 2,
(C) now increment it to 1.
(D) Print 1,
(E) now i=1 and it is less than 2,
(F) now increment it to 2.
(G) Print 2.
(H) now i=2 and it is not less than 2, so drop out of the for loop.
(I) evaluate the while j = 0 and it is less than 2, now increment j to 1 and go back to (A).

Now in (I) when j=2 then it does not go back to (A) anymore and the program is done.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic