Why would you ever use a do while loop

Like in which situation would it be better than just using a while loop.

The example that is often used is a menu that you want to be run atleast once.

Would it not be better in this case to declare a variable, set it to true or whatever, and then inside the loop have a condition that sets it to false to exit ?

Just curious :)

Would it not be better in this case to declare a variable, set it to true or whatever, and then inside the loop have a condition that sets it to false to exit ?


To me, that's more lines of code, and more variables to write.

If i was reading someone's code and trying to understand it I think seeing:

1
2
3
4
do
{

}while( condition);


would be a lot easier for my brain to take in.

i dont use them. I use method the OP stated. That could just be because i jump back and forth between languages that do not have a do-while loop, and i find it a lot easier to use one method through all the languages.
Last edited on
Topic archived. No new replies allowed.