The illustration shows a code segment with "for" loop. The lines numbered 1 through 15 are as follows:
//Illustrates a for loop.
#include <iostream>
using namespace std;
int main( )
{
int sum = 0;
for (int n = 1; n <= 10; n++) //Note that the variable n is a local
sum = sum + n; //variable of the body of the for loop!
cout << "The sum of the numbers 1 to 10 is "
<< sum << endl;
return 0;
} with "n=1" annotated as "Initializing action," "n<= 10" annotated as "Repeat the loop as
long as this is true," and "n++" annotated as "Done after each loop body iteration."
The lines within the "for" loop are highlighted.