+ 1
Can anyone tell me about the while loop and do loop
5 Respuestas
+ 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
+ 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
+ 2
Nafisa Mondal ,
here are 2 links for tutorials from sololearn:
https://www.sololearn.com/learn/CPlusPlus/1617/?ref=app
https://www.sololearn.com/learn/CPlusPlus/1614/?ref=app
+ 2
Ok Thanks everyone
+ 1
C++