| Author |
do while loop problem
|
Jack Lau
Ranch Hand
Joined: Aug 30, 2002
Posts: 166
|
|
Could anyone tell me why it is not an infinity loop ? Thanks in advance! Jack
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jack Lau
Ranch Hand
Joined: Aug 30, 2002
Posts: 166
|
|
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
|
 |
Harwinder Bhatia
Ranch Hand
Joined: Oct 17, 2003
Posts: 150
|
|
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 ]
|
 |
 |
|
|
subject: do while loop problem
|
|
|