+ 2

What is the difference between a do while loop and a while loop?

I know they check the conditions at different times but isn't the output the same? I am confused

2nd Oct 2016, 3:19 AM
jayhaynaynay
jayhaynaynay - avatar
3 Answers
+ 6
The output is the same if the code block inside runs. But it's possible that the condition for a while may be false before it ever gets to run. Using a do/while guarantees that the code inside runs at least once.
2nd Oct 2016, 5:09 AM
Tamra
Tamra - avatar
+ 3
While loop and do-while loop, both are iteration statements which can be used for the same purpose. The difference is that the do while loop gets executed at least once even if the condition is false as the condition is evaluated after running the loop--it is an exit controlled loop, whereas, the while loop doesn't get executed even once if the condition is false because the condition is evaluated before running the loop--it is an entry controlled loop.
2nd Oct 2016, 6:21 PM
Samriddhi Jain
Samriddhi Jain - avatar
0
difference is in do while loop first statement is always execute first but not in while loop.
2nd Oct 2016, 2:13 PM
bidyut