The evolution of if (iii): Algol68, Pascal and C

The design of the if statement in Algol 60 was likely the pinnacle of its evolution. From here on in every language tweaked its syntax, but there were no major changes. Languages like Algol 68, C, and Pascal all had conditional statements. Algol 68, although having the same name as “Algol” moniker, was a different language altogether.

Whereas Algol 60 required the use of explicit compound statements within an if statement if more than one statement was being controlled, Algol 68 incorporated the use of control structure terminators. For the if statement this meant the use of the reversed keyword fi. Algol 68 still lacked the parentheses of Fortran, but also had no requirements for compound statements, as each section was self-delineated. It had the following general form:

if C then
    ...
else
    ...
fi

This had the added effect of eliminating the dangling-else problem of Algol 60. Algol 68 also added the keyword elif, a short-hand to allow for a series of else-if statements:

if C1 then
    ...
elif C2 then
    ...
elif C3 then
    ...
else
    ...
fi

Here is an example:

if x>0 then
    posNum := posNum + 1;
elif x<0 then
    negNum := negNum + 1;
else
    zeros := zeros + 1;
fi

The if statement of C simplified that of Algol 60, deleting the then clause, and adding parentheses to enclose the conditional statement.  It had the following general form:

if (C) 
    statement1; 
else 
    statement2;

However, similar to Algol 60, groups of statements require the use of compound statements delineated by { }, and C also suffers from the dangling-else problem of Algol 60. Here is an example:

if (x>0)
    posNum := posNum + 1;
else if (x<0)
    negNum := negNum + 1;
else
    zeros := zeros + 1;

Pascal, which arrived at a similar time to C, has a syntax similar to that of C – except its logical expression was bracket-less, and it used the then keyword, like Algol 60. Like Algol 60, it also suffered from the dangling-else problem, and required the use of begin-end delineators for a compound statement.

if C then
    S
else
    S2;

 

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