There are three kinds of loops in C++
- While Loops
- Do/While Loops
- For Loops
While Loops
While loops are loops that are executed to when a condition ends the loop.
int i = 0;
while (i < 5)
{
i++;
cout << “i is ” << i << endl;
}
When i gets to 5 the loop will stop.
While Loop Tutorial
Do/while loops
Do/While loops are almost like While Loops except the while statement is executed after the code executes.
int i = 0;
do {
i++;
cout << “i is ” << i << endl;
} while (i < 5);
For Loops
For Loops are while loops in one or two lines codes of code.
for (int i = 0; i < 5; i++) cout << “i is ” << i << endl;
For Loop Tutorial