• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

do while loop problem

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone tell me why it is not an infinity loop ?

Thanks in advance!
Jack
 
author and iconoclast
Posts: 24208
47
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The continue goes to the condition -- i.e., the "(flag)? true:false" is evaluated next. You're assuming that continue always goes to the top of the loop, which isn't so; it goes to the beginning of the next iteration, which starts with evaluating the condition.
 
Jack Lau
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh, that means
do {
continue; // will go to (flag)?
} while ((flag)?true:false);
while ((a+b > 1)) {
continue; // will go to (a+b > 1)
}
for (int i=0; i<10; i++) {
continue; // will go to (i<10)
}
Am I right ?
Thanks!
Jack
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right on 'do' and 'while' loops but for 'for':
'continue' will first go to 'i++' and then 'i<10'
-H
[ October 27, 2003: Message edited by: Harwinder Bhatia ]
 
Paper beats rock. Scissors beats tiny ad.
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic