C++ for loops is very similar to a while loops in that it continues to process a block of code until a statement becomes false, and everything is defined in a single line. for loop is an entry-controlled loop.
The basic format of for loop statement is:
Syntax:
for ( init; condition; increment )
{
statement(s);
}
Figure - Flowchart of for loop:
Example of a C++ Program to Demonstrate for loop
Example:
#include <iostream>
using namespace std;
int main ()
{
/* local variable Initialization */ int n = 1,times=5;
/* for loops execution */ for( n = 1; n <= times; n = n + 1 )
{
cout << "C++ for loops: " << n <<endl;
}
return 0;
}
Program Output:
Here are few other related articles for you to read: