Loop is used to repeat a statement or more statements. There are three loops in C++.
Do While
Do while almost similar with while. But, it always execute statement because do-while will check condition after all statements executed.
#include <iostream>
using namespace std;
int main(){
int numr=10;
do{
cout << numr << endl;
numr++;
}while(numr<=10);
cout << "finished";
return 0;
}
Example :
10 finished
If you use while, it won't print numr's value because the condition is false from the beginning.
#include <iostream>
using namespace std;
int main(){
int numr=10;
while(numr<=10){
cout << numr << endl;
numr++;
}
cout << "finished";
return 0;
}
Example :
finished