For loop in C++ language
- The for loop is the easiest C++ loop to understand. All its loopcontrol elements are gathered in one place, while in the other loop constructions they are scattered about the program, which can make it harder to unravel how these loops work.
- The for loop is a generic iterator in C++, it can step through the items in any ordered sequence or other iterable object.
- A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
for(initialization; expression; increment)
// demonstrates simple FOR loop
#include using namespace std;
int j; //define a loop variable
for(j=0; j<15; j++) //loop from 0 to 14,
cout << j * j << “ “; //displaying the square of j
cout << endl;
0 1 4 9 16 25 36 49 64 81 100 121 144 169 196