Evolution of if (iv): Ada and beyond

By 1977, Fortran had likely its greatest metamorphosis from an unstructured, to a quasi-structured language. At the eleventh hour the revision for the F77 standard was modified to reduce the impact of goto statements to match other languages, where its influence was minimal, or even non-existent. The changes made Fortran 77 vastly different from its predecessor, Fortran 66.

Of major importance, was the inclusion of a “block IF“, which took the following form:

IF (E) THEN
...
END IF

The use of THEN as a new keyword allowed a block of statements to be incorporated until the terminating keyword ENDIF was reached. This also solved the dangling else problem. This was augmented by the addition of the keyword ELSE, which allowed for a group of statements to be actioned if the preceding IF is not satisfied.

IF (E) THEN
    ...
ELSE
    ...
ENDIF

By the mid-70s, Fortran was likely coerced into making these changes due to the competition from C and Pascal, both of which offered these conditionals. These new F77 constructs allowed for improved program readability, especially through eliminating the need for statement labels, and goto statements. Here is an example:

IF (K.GT.0) THEN
    POSNUM = POSNUM + 1
ELSE IF (K.LT.0) THEN
    NEGNUM = NEGNUM + 1
ELSE
    ZEROS = ZEROS + 1
ENDIF

The emergence of Ada did nothing to evolve the if statement. Like Pascal and F77, it used a then keyword, borrowed the else-if idea from Algol68, renaming it elsif, and used the same structure terminator endif, as F77. By this stage, if statements had likely evolved as far as they would, and new languages were just selecting appropriate concepts from existing languages.

if C1 then 
    S1 
elsif C2 then 
    S2
elsif Cn then 
    Sn
else 
    S(n+1)
endif;

Fortran 90 would go on to finally make  the arithmetic if  obsolescent. Python would alter very little, adopting the elif of Algol68, and the lack of parentheses.

if x == 0:
    zeroes = zeroes + 1
elif x < 0:
    negnum = negnum + 1
else:
    posnum = posnum + 1

Julia as well uses an amalgam of structural pieces.

if x < 0
    negnum = negnum + 1
elseif x > 0
    posnum = posnum + 1
else
    zeroes = zeroes + 1
end

We are now in the age of mix-and-match, and it is unlikely the if statement will evolve to any great extent.

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