do-while

Test loops at the top or bottom? (while vs. do while)

When I was taking CS in college (mid 80's), one of the ideas that was constantly repeated was to always write loops which test at the top (while...) rather than at the bottom (do ... while) of the loop. These notions were often backed up with references to studies which showed that loops which tested at the top were statistically much mo...

does continue work in a do while?

I have a do while that looks like: User user = userDao.Get(1); do { // processing // get the next user // user = UserDao.GetNext(user.Id); if(user == null) continue; // will this work????????????? } while ( user != null) If it does work, its going to go to the top of the do statement, and user is null so things are g...

Why use a "do while" loop?

Hi, I've never understood why using a do while loops is necessary. I understand what they do, Which is to execute the code that the while loop contains without checking if the condition is true first. But isn't the below code: do{ document.write("ok"); } while(x == "10"); The exact same as: document.write("ok"); while(x == "10"...

Is "}while(0);" always equal to "break;}while(1);" ?

I have compared gcc assembler output of do{ //some code }while(0); with do{ //some code break; }while(1); The output is equal, with or without optimization but.. It's always that way? No experiment can prove theories, they can only show they are wrong And because (I hope) programming is not an experimental science, and...

Doubts in a code using do while loop

Hi All, This is a small piece of code shown below which is using do while loops. I really dont understand the unexpected behaviour i see when i execute this code.This code shown below uses a do while loop condition and from my knowledge a do while loops executes in such a way that if first executes the statement and then checks in the w...

When should I use do-while instead of while loops?

Possible Duplicates: Is there ever a need for a do {} while ( ) loop? Do your loops test at the top or bottom? While vs. Do While When is a do-while appropriate? I've been having a philosophical debate with a colleague as to whether as a general rule, in C/C++ we should should use while loops rather than do-wile loops. ...

PHP Text area foreach line

Im trying to code a php script that will loop a process for each line in a Textarea post. I was wondering if someone can post an example. ...

do...while vs while

Possible Duplicates: While vs. Do While When should I use do-while instead of while loops? I've been programming for a while now (2 years work + 4.5 years degree + 1 year pre-college) and I've never used a do-while loop short of being forced to in the Introduction to Programming course. I have a growing feeling that I'm doin...

how does do{} while(0) work in macro?

Though this topic has been discussed many times in this forum and all other forums, still I have doubts. Please help. How does the do{} while(0) in macro work in Linux kernel? For example, #define preempt_disable() do { } while (0) How does it disable preempt? #define might_resched() do { } while (0) How does it reschedule?...

Minimize loops in reference to read/write operations

Hi, the last thing I want to minimize today is code that contains while and do-while loops. Here is the original: class Vereinfache3_edit { public static void main(String [] args) { int c1 = Integer.parseInt(args[0]) ; int c2 = Integer.parseInt(args[1]) ; int c3 = Integer.parseInt(args[2]) ; ...