Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
1.19/5 (4 votes)
See more:
What is the difference between do while and while do loop?
Posted
Comments
Andreas Gieriet 14-Oct-13 6:02am    
Any idea yourself?
E.g. write the two loops:
while do:
while (false) { printf("block\n"); }
do-while:
do { printf("block\n"); } while (false);

Cheers
Andi
Richard MacCutchan 14-Oct-13 7:18am    
That's a +5 solution.
Andreas Gieriet 14-Oct-13 9:54am    
Thanks for your "virtual" 5! ;-)
Cheers
Andi
thatraja 14-Oct-13 6:04am    
Google it :(

Check this answer of this link.
 
Share this answer
 
Have you ever bothered writing those 2 loops ? I bet you have not. Your question can be clarified using only the names of the loops: Do While and While Do(usually called the while loop).

1. Do While - Do *something* while *this is true*
C++
do
{
   //what's here
}
while(/*this is true*/)

2. While Do - While *this is true* Do *something*
C++
while(/*this is true*/)
{
   //do what's here
}



In the Do While loop, first the loop body is executed and then the condition is checked.

In the While (or While Do as you called) loop, first the condition is checked and then runs the body loop.
 
Share this answer
 
Do While:

The do while loop executes the content of the loop once before checking the condition of the while.

Procedure goes like this:
. Run the code in the body of the loop.
2. Check the condition. If it's true, go to step 1. Otherwise, move on.



While:
A while loop will check the condition first before executing the content.

Procedure goes like this:
1. Check the condition. If it's true, go to step 2. Otherwise, move on.
2. Run the code in the body of the loop.
3. Go to step 1.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900