The evolution of if (ii): Fortran IV and 66

Fortran did not make any inroads into modifying the if statement until later. Likely spurned on by Algol 60, Fortran IV introduced the logical if statement in 1965. It had the following form:

IF (E) STATEMENT

Where E was a logical expression, using operators of the form .EQ. for =, and .LE. for ≤. The statement was any statement except a DO statement or another logical IF. However unlike Algol 60, there were no compound statements, and no keyword corresponding to else. Both these had to be achieved by means of goto statements. In this sense it almost mimicked an if-else statement. Consider the example below:

    IF (A .LE. 0) GOTO 15
    W = X ** A
    GOTO 20
15  W = 0
20  ...

In this case, if the value of A is less than of equal to zero, the program jumps to statement 15, setting W to 0. Otherwise it calculates W=X**A, and jumps to statement 20. Notice that the Fortran conditional “operators” are stropped by the use of periods, e.g. .EQ.. This was done to avoid potential ambiguity. The expression A LE 0 could also have been interpreted as the variable ALE0. Fortran 66, the first industry standard made no changes to the if statement.

There were a number of differences between Fortran (IV) and Algol (60):

  1. Fortran used mnemonics to represent conditional operator, e.g. .LE., versus Algol’s ≤ (in some implementations <= was used due to the non-availability of ≤)
  2. Fortran uses parentheses, ( ),  to separate the logical expression from the statement, whereas Algol uses the additional keyword then.
  3. Fortran (66) required that each arithmetic statement on either side of a conditional be of the same datatype. This is because A.GT.B was often translated to A-B.GT.0.(This disappeared in F77).

By all accounts, Fortran IV, and 66 were extremely deficient with respect to conditional statements. The next major changes were not to appear until Fortran 77.

Consider code that looked like this in Algol 60:

if k>0 then posNum := posNum + 1
       else if k<0 then negNum := negNum + 1
                   else zeros := zeros + 1

The equivalent in Fortran 66 would be:

    IF (K.GT.0) GOTO 30
    IF (K.LT.0) GOTO 31
    ZEROS = ZEROS + 1
    GOTO 47
30  POSNUM = POSNUM + 1
    GOTO 47
31  NEGNUM = NEGNUM + 1
75  ...

How did if evolve in other languages? Algol 68, C, Pascal?

 

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