The do...while loop is a variation of the while loop with one significant distinction: the body of do...while loop is executed once before the condition is checked.
Syntax:
do{
// body of loop;
}
while (condition);
Here,
The body of the loop is executed from the start. Then the condition is assessed.
If the condition assesses to true, the body of the loop inside the do statement is executed once more.
The condition is assessed once again.
If the condition assesses to true, the body of the loop inside the do statement is executed once more.
This process continues until the condition assesses to false. Then the loop stops.
Example : Display Numbers from 1 to 10
//C++ Program to print numbers from 1 to 10
#include <iostream>
using namespace std;
int main()
{
int i = 1;
// do...while loop from 1 to 10
do
{
cout << i << " "; ++i;
}
while (i <= 10);
return 0;
}
Output
12
3
4
5
6
7
8
9
10
0 Comments
🙏🙏please don't enter any spam links on the comment box.....