+ 2
Hey please whats is the difference between do while loop and while loop
7 odpowiedzi
+ 2
while () {} : It is an entry control loop i.e the condition is checked before entering into loop
whereas do {} while() ;is exit control loop the conditions are checked at the end of do scope i.e after executing the do.. body
Suppose this piece of code in cpp
int i = 2;
while(i < 1) // 2 < 1
//false so it doesn't enter inside while
{
cout << "Inside while " ; // this line isn't printed
}
do{
//enters do.. while body regardless of condition
{
cout << "Inside do while " ;//prints
} while (i < 1); // checks : 2 < 1 which is false. Loop terminates
+ 10
//search for the question , U will find many more 👍
https://www.sololearn.com/Discuss/1126330/?ref=app
+ 3
okeeey i get it now thank you bro
+ 2
Thw while loop verifies rhe condition before the statements in the loop are executed.
The do while loop execute the statements before checking the condition.
Say: x = 0
do{
System.out.print(x);
}while(x != 0);
while(x != 0){
System.out.print(x);
}
In the first case 0 will be printed, then the condition checked. It will return false so the statement in the loop will no longer be executed.
In the second case 0 will never be printed cause the condition returns false so no statement in the loop is executed
+ 2
they said that do while loop can run your programme once a time please can u explain it to me
+ 2
Yes. Sure. Because the condition is checked after the statements in the loop are executed, they are executed at least one time.
Like in the example I gave you. Though the condition is not true the loop executed once.
0
If the condition specified for the loop is false,while loop will not run at all. But do while loop iterates at least once even if the condition is false,because condition gets checked at the end.