+ 1

How is while loop different from do while?

16th Oct 2016, 5:58 PM
Neha Bit
Neha Bit - avatar
2 Answers
+ 6
A do while loop is garanteed to loop at least once, as the condition is checked at the end of the loop rather than at the beginning. Also, because of that, you can modify the parameters of the condition in the loop before it is checked, which is handy if the condition is false at the beginning of the loop but you still want to loop anyway. For example: int a = 0; do { cout << a << endl; a++; } while (a%4 != 0);
16th Oct 2016, 6:12 PM
Zen
Zen - avatar
+ 5
in do while loop the condition is checked after the execution whereas in while loop first condition is checked then execition is done... if in do while loop the condition is false yet it will execute the program once..
17th Oct 2016, 6:29 AM
gurinder sandhu
gurinder sandhu - avatar