The do-while Loop
{
statement;
}
while(test_expression); //Put semicolon after while statement
Program:
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr(); // For clear screen
int num=1;
do {
cout<<num<<"\n";
num++;
}
while(num<10);
getch();
}
Output:
12
3
4
5
6
7
8
9
The do while loop will run as long as 'num' is smaller than 10.
You can ask questions if you have doubts regarding C++.
No comments:
Post a Comment