[Next] [Up] [Previous]

The IF Statement

The form of the IF statement is as follows:

       IF logical-expression,alt-true,alt-false

where an arithmetic-expression is an integer or floating-point expression of any precision; that is, any numeric expression that is not complex or quaternion.

Recommended @-comments (if used):

       IF logical-expression @THEN, alt-true @ELSE, alt-false

These may also be used as &'...' replacements:

       IF logical-expression &'THEN' alt-true &'ELSE' alt-false

but the @-comment form is shown first as the continued presence of the old special character in that form makes it clear what is being replaced.

Alt-neg is the alternative taken if the expression is negative, alt-zero if zero, alt-pos if positive; alt-true if true, alt-false if false.

Each alternative may have one of four forms:

Note that even ONE statement must be enclosed in statement brackets, since their function is to render one or more statements equivalent to a statement number. This is different from the function of BEGIN and END in Algol, Pascal, and so on, where statement brackets make more than one statement equivalent to one statement. However, @BEGIN{ and @END} are still the recommended @-comments there, despite the difference in meaning. This particular form of alternative is called a sequence, and both sequences and alternatives which may or may not be sequences will be encountered in other EXALT statements and constructs.

If the opening statement bracket in an alternative is preceded by a period, this indicates that that alternative is a low-priority alternative. Thus, a compiler that compiles

       IF LV, {. V=V+1},{. V=V-10,. U=_SIN(V+.001*R)}

into something like

       IF LV,*,100010
       . V=V+1
       GO_TO 100020
100010 . V=V-10
       . U=_SIN(V+.001*R)
100020 ...

would be expected to compile the statement

       IF LV,{. V=V+1},.{.V=V-10,. U=_SIN(V+.001*R)}

into something like

       IF LV,*,100010
       . V=V+1
100020 ...
       ... (all the rest of the program)
100010 . V=V-10
       . U=_SIN(V+.001*R)
       GO_TO 100020

so that the alternative designated as lower priority would get two jump instructions, while the other, higher-priority, alternative would get two time-saving fall-throughs.

Considering that this type of situation was the reason for adding the much-criticized construct of the 'extended range' of a DO statement to FORTRAN, it seems legitimate to add a priority designation to the language to gain the same efficiencies at no loss in program readibility. (However, branching in and out of the areas affected by FOR statements is also allowed in EXALT; reasons for allowing programmers to avoid an undesirable practice are not necessarily sufficient for prohibiting the practice entirely.)

Note that a useful result is achieved when either none, one, or two alternatives in an IF statement (or one of the related statements below) is an undotted sequence; if none, fall-through from the IF statement requires no jumps; if one, the case is as shown above: the preferred alternative gets two fall-throughs; if two, each of the two preferred alternatives gets one fall-through, any other sequences requiring two jumps, one in and one out.


[Next] [Up] [Previous]