+ 1

Can anyone tell me about the while loop and do loop

25th Aug 2021, 8:14 AM
Nafisa Mondal
Nafisa Mondal - avatar
5 odpowiedzi
+ 4
okay let me explain you with one Example Lets take a integer Variable named as i and assigned with value 15 while(i<10) //condition fails since i value is greater than 10 { cout<<"Hello World"<<endl; i - -; } so Hello World will not be printed in the output since loop is not executed do //condition is not checked at this movement so control goes into the loop { cout<<"Hello World"<<endl; //printed for the first time i - -; } while(i<10); //condition checked now. It fails since i value is greater than 10 so loop will not be executed so we can conclude that if the condition fails then the while loop will not be executed but the do-while will executed atleast ones even though the condition fails
25th Aug 2021, 9:29 AM
Ur-Wellwisher
Ur-Wellwisher - avatar
+ 2
Obvious difference between ' do.. while loop' and "while loop" is 'do.while' loop run one time even though the condition is false, but "while loop" not
25th Aug 2021, 8:34 AM
Myo Thuzar
Myo Thuzar - avatar
25th Aug 2021, 3:17 PM
Lothar
Lothar - avatar
+ 2
Ok Thanks everyone
26th Aug 2021, 7:02 AM
Nafisa Mondal
Nafisa Mondal - avatar
+ 1
C++
25th Aug 2021, 8:26 AM
Nafisa Mondal
Nafisa Mondal - avatar