What is a loop ?
In computer programming, loops are used to repeat a block of code.
For example, let’s say we want to show a message 100 times. Then instead of writing the print statement 100 times, we can use a loop.

Types of loops -
1.For loop
for(initialization; condition ; increment/decrement)
{ C++ statement(s); }
Example -

Output

2. Do while loop
do {
// Code block to be executed
}
while (condition);
Example -
#include <iostream>
using namespace std;
int main() {
int i = 0;
do {
cout << i << endl;
i++;
}
while (i < 5);
return 0;
}
Output
0
1
2
3
4
3.while loop
while(condition) { statement(s); }
Example -
#include <iostream>
using namespace std;
int main ()
{
int a = 10;
while( a < 20 )
{ cout << "value of a: " << a << endl;
a++;
}
return 0;
}
Output
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19