FORTRAN IV programming hints

Source line format


1Comment line indicator; 'C' for comment line (compiler ignores rest of line)
1-5Statement label (numeric)
6Line continuation indicator; blank or '0' for initial line, other non-blank for continuation lines (up to 19)
7-72Statement text

DEC FORTRAN-10 supports an alternative source line format (comment line format same as standard above):

Single-line statement or initial line of multi-line statement:[<label>] <tab> <statement text>
Continuation of multi-line statement:
(<cont. indicator> must be single-digit number)
<tab> <cont. indicator> <statement text>

Character set

A-Z 0-9 ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ ^ <space>

Format field descriptors

DescriptorInternal form External form
nDw.ddouble-precision floating pointfloating point with "D" exponent
nEw.dfloating pointfloating point with "E" exponent
nFw.dfloating pointfixed point
nOwintegeroctal integer
nGw.dOne of:
floating point

floating point
nTp-Start next field at position p-1
wX-space/skip input
/-record separator
$-(at end of record) Suppress carriage return

Optional modifiers:

nField repeat count; may repeat group of fields with notation "n(<descriptor>...)"
wField width
dDecimal places; For G descriptors, significant digits

Format printing control

A one-character alphanumeric item, or the first character of a longer alphanumeric item at the beginning of a format list can be used for print control:

<space>Start printing at the beginning of the next line.
0Skip a line.
-Skip two lines.
+Overprint current line.
1Start printing at top of next page.
2Skip to next 1/2-page.
3Skip to next 1/3-page.
/Skip to next 1/6-page.
*Skip to next 1/10-page.
.Skip to next 1/20-page.
,Skip to next 1/30-page.

Structured programming

The FORTRAN IV programming language as specified lacks much explicit support for structured programming techniques, but a disciplined use of the provided program statements can produce structured programs and avoid spaghetti code nonetheless.

The following code snippets show how to produce structured programming constructs with FORTRAN IV statements. Bear in mind that for some of these constructs the sense of tests is reversed from those in standard structured programming languages.

(Statement labels must be unique in a given program unit (main program, subroutine, function).)

Sequential structures

FORTRAN IV statement execution is sequential by default. Avoid unstructured use of GO TO statements.

Selection structures

1. Single-statement consequent (standard logical IF statement)

IF (<condition>) <statement>
... or multiple statements can be executed if packaged in a subroutine:
IF (<condition>) CALL <subroutine>

2. Multiple-statement consequent (<condition> is condition to execute consequent statements)

IF (.NOT.<condition>) GO TO 10

3. Alternative block

IF (<condition>) GO TO 10
 <alternative statements>
 GO TO 20
 <consequent statements>
Note that order of consequent and alternative blocks is reversed from that in most structured programming languages.

4. Multiple alternatives (case/switch); condition represented by integer value in ICOND (computed GO TO):

GO TO (10, 20, 30), ICOND
 <default statements>
 GO TO 40
 <condition=1 statements>
 GO TO 40
 <condition=2 statements>
 GO TO 40
 <condition=3 statements>
Note that default block appears first where in most structured programming languages it appears after all alternative blocks.

5. Multiple alternatives; arbitrary condition:

IF (<condition 1>) GO TO 10
IF (<condition 2>) GO TO 20
IF (<condition 3>) GO TO 30
 <default statements>
 GO TO 40
 <condition 1 statements>
 GO TO 40
 <condition 2 statements>
 GO TO 40
 <condition 3 statements>
Note that default block appears first where in most structured programming languages it appears after all alternative blocks.

Iteration structures

6. Counted loop (standard DO loop):

DO 10 I = <initial>, <limit>[, <increment>]