Early years of the for loop

As discussed in a previous post, the for loop likely evolved our of Rutishauser’s use of a für statement in his algorithmic language Superplan. It even used a terminating phrase to form a rudimentary form of block structure.

Für k=1(1)n :
   ...
Ende Index k

When Fortran appeared, it did not have a for loop, but rather a DO structure – I use the term structure, because it relied on labels to form a structure of sorts, not a true loop.  The use of the word for is interesting because it doesn’t explicitly say “loop” but rather likely refers to its preposition form “over a period of time”. Rutishauser worked on the committee developing Algol, so it is not surprising that the Für loop found its way into the language syntax. In ALGOL [58] the for statement had the form:

for i := 1(1)n; p := p × y + A[i]

Which was very similar in structure to the Für loop of Superplan, excepting that “:=” was used instead of “=”. Also in Superplan, the loop was bounded by “Ende index x”, Algol assumed a single statement following the loop. Interestingly, the for loop in Algol 58 had a second form, which allowed a list of expressions. For example:

for a := 1, 3, 5, 9.76, ...,-12.75;

Algol 60 modified this slightly, replacing the parentheses with keywords, and using the do keyword to denote the beginning of the controlled statement (and end of the for-clause):

for i := 1 step 1 until 100 do
    statement;

Algol 60 introduced compound statements which allowed for blocks of statements in the loop body:

for k := 1 step 2 until n do
begin
    e[k] := (e[k]/q[k]) * q[k+1];
    q[k+1] := (q[k+1] - e[k]) + e[k+1]
end

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s