You are here

An Example

10 February, 2015 - 12:14

Example 15.1: C++ source code: for

for (counter = 0; counter  <  5; counter++)   {    cout << "\nI love ice cream!";   } 

The four attributes of a test before loop (remember the for loop is one example of a test before loop) are present.

  • The initialization of the fag to a value of 0.
  • The test is the less than relational comparison of the value in the fag variable to the constant value of 5.
  • The action part consists of the 1 line of output.
  • The update of the fag is done with the increment operator.

Using indentation with the alignment of the loop actions is normal industry practice within the C++ community.