The basic arithmetic operations of addition, subtraction, multiplication,
division, and exponentiation (raising to a power) are all possible in
FORTRAN 77. Addition and subtraction in FORTRAN 77 use the same
familiar symbols `+`

and `-`

. However, multiplication
(which is denoted in a variety of ways in mathematics) is represented in
FORTRAN 77 by an asterisk `*`

and division by a forward slash
`/`

. A double asterisk `**`

is employed to raise a
base to a power.

Priority | Operation | Symbol | FORTRAN 77 Expression | Arithmetic Expression |
---|---|---|---|---|

inside to outside | Parentheses | `( )` |
||

right to left | Exponentiation | `**` |
`A**B` |
a^{b} |

left to right | Multiplication and Division | `*` |
`A*B` |
a×ba÷b |

left to right | Addition, Subtraction, and Unary Minus | `+` |
`A+B` |
a+ba-b-a |

Parentheses have the highest priority and can be used to force lower priority calculations to occur before higher priority ones.

The arithmetic expression *-a ^{n}+b×c-d÷e* is
written in FORTRAN 77 as

`-A**N+B*C-D/E`

and is evaluated
in the following order:
`A**N`

`B*C`

`D/E`

`-`

in front of`A**N`

`+`

between`-A**N`

and`B*C`

`-`

between`B*C`

and`D/E`

The arithmetic expression *a+(b ^{m})^{n}/(c-d)*
is written in FORTRAN 77 as

`A+((B**M)**N)/(C-D)`

and is
evaluated in the following order:
`B**M`

- raise
`B**M`

to the`N`

power `C-D`

`/`

between`(B**M)**N`

and`C-D`

`+`

between`A`

and the rest of the expression

Here parentheses are used to override the default priorities.

Use as many parentheses as necessary to make the expression clear. Note that only parentheses are used in FORTRAN 77. Neither square brackets [ ] nor curly braces { } are used.

Two `CHARACTER`

strings can be joined together in a process
called **concatenation**. The concatenation operator is a double
forward slash `//`

.

The two strings `'FORT'`

and `'RAN'`

can be
combined as `'FORT'//'RAN'`

to give `'FORTRAN'`

.

The concatenation operator can be used on `CHARACTER`

constants
(as in the above example) or on `CHARACTER`

variables. Any
number of strings can be combined into one string using this operator.

A **substring** is any string that is a subset of the original
stringand maintains the order of the original. The notation
*variable(a:b)* indicates a substring of the `CHARACTER`

variable *variable* starting at the *a ^{th}* character
and ending at the

Suppose the `CHARACTER`

variable `BEST`

has length
7 and has been assigned the value `FORTRAN`

. Then
`BEST(6:6)`

gives the value `A`

and
`BEST(1:4)`

gives `FORT`

.

Three operations can be performed on `LOGICAL`

variables:
**negation**, **and**, and **or**.
To negate a `LOGICAL`

expression, precede it with
`.NOT.`

When two `LOGICAL`

expressions are combined
with an `.AND.`

, then the result is `.TRUE.`

only if both
parts are `.TRUE.`

Two `LOGICAL`

expressions
combined with an `.OR.`

yield `.TRUE.`

unless both
parts are `.FALSE.`

The **truth table** below sums
this up:

A | B | .NOT. A | A .AND. B | A .OR. B |
---|---|---|---|---|

`.TRUE.` |
`.TRUE.` |
`.FALSE.` |
`.TRUE.` |
`.TRUE.` |

`.TRUE.` |
`.FALSE.` |
`.FALSE.` |
`.FALSE.` |
`.TRUE.` |

`.FALSE.` |
`.TRUE.` |
`.TRUE.` |
`.FALSE.` |
`.TRUE.` |

`.FALSE.` |
`.FALSE.` |
`.TRUE.` |
`.FALSE.` |
`.FALSE.` |

`.NOT.`

has the highest precedence, followed by
`.AND.`

and then `.OR.`

A `LOGICAL`

expression may contain several logical operators, and parentheses may
be used to override default precedences.

The FORTRAN 77 expression

A .OR. .NOT. (B .OR. C) .AND. D

where all of the variables are of type `LOGICAL`

is evaluated
in the following order:

`B .OR. C`

`.NOT.`

in front of`B .OR. C`

`.AND.`

between`.NOT. (B .OR. C)`

and`D`

`.OR.`

between`A`

and the rest of the expression.

If the parentheses were absent, then the evaluation order of

A .OR. .NOT. B .OR. C .AND. D

would be

`.NOT. B`

`C .AND. D`

`.OR.`

between`A`

and`.NOT. B`

`.OR.`

between`.NOT. B`

and`C .AND. D`

Note that it is possible to have two `LOGICAL`

operators
next to each other provided the first is an `.AND.`

or an
`.OR.`

and the second is `.NOT.`

Relational operators compare two expressions of a similar type and
evaluate to either `.TRUE.`

or `.FALSE.`

Comparing Numbers | Comparing Booleans | ||
---|---|---|---|

Operator | Meaning | Operator | Meaning |

`.EQ.` |
equal to | `.EQV.` |
equivalent to |

`.NE.` |
not equal to | `.NEQV.` |
not equivalent to |

`.LT.` |
less than | ||

`.LE.` |
less than or equal to | ||

`.GT.` |
greater than | ||

`.GE.` |
greater than or equal to |

Every character in a program is represented internally as a binary
number. There are a number of different codes for translating characters
into binary strings but the two most commonly used are **EBCDIC**
(Extended Binary Coded Decimal Interchange Code) and **ASCII**
(American Standard Code for Information Interchange). Because every code
has a different collating sequence, it is impossible to use the
relational operators to try to compare two `CHARACTER`

strings alphabetically. However, FORTRAN 77 provides a number of
intrinsic functions that permit alphabetical comparisons of two strings
based on the ASCII code, regardless of which code the computer actually uses.

A `LOGICAL`

expression is defined when two numbers are compared
using one of the relational operators. These `LOGICAL`

expressions can be combined into a compound `LOGICAL`

expression
by using the `LOGICAL`

operators defined above.

To test whether a value *a* is less than 2.0, or greater than or
equal to 5.0, write

A .LT. 2.0 .OR. A .GE. 5.0

The relational operators `.LT.`

and `.GE.`

have a
higher priority than the `LOGICAL`

operator `.OR.`

However, parentheses such as these

(A .LT. 2.0) .OR. (A .GE. 5.0)

might make the logic clearer.

To test whether either *a* or *b* are negative `REAL`

numbers, you cannot write

A .OR. B .LT. 0.0

because the `LOGICAL`

operator `.OR.`

can only be used
between two `LOGICAL`

expressions. In this instance,

B .LT. 0.0

returns a `LOGICAL`

expression which leaves the comparison

*numerical expression* `.OR. LOGICAL`

*expression*

Instead, write

A .LT. 0.0 .OR. B .LT. 0.0

The `.EQV.`

relational operator is true if both operands are
identical, i.e. if both are true or if both are false. The
`.NEQV.`

relational operator is the negation of `.EQV.`

.
It is true only if one operand is true and the other is false. It is also
known as **exclusive OR**. Note how it differs from
`.OR.`

, which is true if either or both operands is true.

A | B | A .EQV. B | A .NEQV. B |
---|---|---|---|

`.TRUE.` |
`.TRUE.` |
`.TRUE.` |
`.FALSE.` |

`.TRUE.` |
`.FALSE.` |
`.FALSE.` |
`.TRUE.` |

`.FALSE.` |
`.TRUE.` |
`.FALSE.` |
`.TRUE.` |

`.FALSE.` |
`.FALSE.` |
`.TRUE.` |
`.FALSE.` |