aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes do while loop problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "do while loop problem" Watch "do while loop problem" New topic
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
    
  13

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: do while loop problem
 
Similar Threads
Use Of Continue in do While Loop
Flow Control
Play again function help?
Confusion again???
what's the continue functionality in do/while loop?