The FORTRAN Programming Language 

 

Handling of Sequence Control  

Mathematical Operators and Precedence
FORTRAN provides operators for addition, subtraction, multiplication, division, and exponentiation. Binary and unary operators have the same precedence. Using parenthesis can change operator precedence.

Logical Operators
FORTRAN provides logical operators for not, and, and or. Their representation and precedence is below. The exclusive or operator, .NEQV. is also provided.

( )

.NOT.

.AND.

.OR., .NEQV.

Relational Operators
FORTRAN uses two characters surrounded by periods for its relational operators. FORTRAN 90 also has mathematical symbol representations.

Operation

Operator

FORTRAN 90

Equal

.EQ.

==

Not Equal

.NE.

/=

Greater Than

.GT.

>

Less Than

.LT.

<

Greater than or equal

.GE.

>=

Less than or equal

.LE.

<=

Labels and Goto Statement
FORTRAN makes extensive use of GO TO statements using unsigned integer constants for labels. Functions and procedures can therefore have multiple entrances. This is flexible, but detrimental to readability and error prone.

Short-circuiting of Expressions
When evaluating logical expressions, FORTRAN may employ short-circuiting of the expression, however if a function is left unevaluated, its value may be set to undefined.

IF statement
FORTRAN IV began with a simple one-way IF selector: 

IF (Boolean expression) statement

Only one statement was selectable, and nesting was not an option. In the 1960's ALGOL had introduced 2-way selection with their else statement. Soon other imperative languages followed suit. FORTRAN 90's IF selector now allows nesting and provides a method to represent a series of nested 2-way selectors that is very readable.

IF (<logical expression>) THEN

<statements>

ELSEIF (<logical expression>) THEN

<statements>

...

<statements>

ENDIF

IF 3-way
FORTRAN provides a degenerate multiple selector called the 3-way arithmetic IF. The statement has the format: 

IF (arithmetic expression) <N1>, <N2>, <N3>

Where the N values are labels that direct control when the value of the expression is greater than, equal to, and less than 0 respectively. The different cases are terminated with GO TO statements that direct control to the next part of the program. While this is very flexible, it does not provide a single entry point, nor insure that only one of the cases will be selected.  

Computed GOTO and Multiple Selection
FORTRAN's original multiple selection statement takes the form:

GOTO (<label 1>{,< label n>}), <expression>

The expression is evaluated and the labels serve as positional identifiers for possible results. The first label is associated with the value, 1, the second, 2 , etc. If the expression evaluates to a value greater than n, the entire selection is ignored. FORTRAN also provides a similar assigned GO TO. As in the 3-way IF, both of these provide the possibility of multiple entry points and selection of more than one of the cases.

FORTRAN 90 provides a case statement similar to Ada. It allows for value ranges and value lists for each case. It requires that the list be exhaustive, but provides a default case if the others do not apply.

SELECT CASE (<expression>)

CASE (<first list of values>)

<statements>

CASE (<second list of values>)

<statements>

...

CASE DEFAULT

<statements>

END SELECT

The default step size is 1, and the parameters are all unsigned integers or integer variables with positive values. Label is the label number assigned to the last statement in the loop. FORTRAN 90 allows replacement of the label value with a closing special word, END DO. The FORTRAN 90 loops and closing statements can be named to avoid ambiguity.

No Logical Loops
Neither FORTRAN 77 or FORTRAN 90 provide posttest or pretest logical loops officially as part of the language. These statements must be constructed using DO loops, IF statements and GO TO exits. However, some compilers allow for both pre-test and post-test logical loops.