+ 1
do .. while is used for what?? What do.. while function?
3 Respostas
+ 2
do-while is while except do-while would execute at least once. You can always use either while or do-while. For me, it's just a style of programming.
Comparation:
do {
cout << "Hello";
}
while(1+1==3) //Output: Hello
while(1+1==3) {
cout << "Hello"
} //No output.
+ 2
If you need a loop that will execute at least once regardless of the condition inside the brackets being âtrueâ or âfalseâ or you need the condition to be checked at the end of each loop, then you use the âdo...whileâ loop.
0
A 'do... while' loop is the exact same as a regular 'while' loop but it will always execute at least once.
Int x = 1;
do
{
cout << "hi";
}while(x = 0)
Here, even though the condition is false, it runs the code then checks the condition, so it executes only one time.