0

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.

My feeling is that the only time you should use a do-while is if you need to repeatedly test the same thing and you will always want to do so at least once. Generally I always felt that a while loop is more readable.

I realise this could be considered a somewhat subjective / personal style thing, but I'd be interested to hear anyone's thoughts as to whether I'm right or mising something here. Concrete examples would be especially welcome.

Community
  • 1
  • 1
Jon Cage
  • 36,366
  • 38
  • 137
  • 215

0 Answers0