You are here

Miscellaneous Information about the for Structure

10 February, 2015 - 12:25

Many languages (Pascal, FORTRAN, and other) have a for loop structure that is used exclusively for counting. The for loop in the C++ programming language is much more versatile and can be used (and generally is used) in place of the while loop structure. In reality a counting loop is just a particular use of a while loop.

The name for comes from mathematics' method of writing an iteration (or repetition). In math we would say: "For the variable i starts at a given value and repeats an action increasing the value of i until i is executed for the stopping value". Usually written in math as:

for i = 1 to 5 do some action

Note: here the means equals not assignment. Another way to say it is that i varies from 1 to 5.