The structure of a FORTRAN program

A FORTRAN program is made up of several parts:


A FORTRAN program may also contain comments. These are documentation, ignored by the compiler. Comments are for human readers.

To create a comment, use an exclamation point (!). Everything from the exclamation point to the end of the line is a comment. Comments often begin in column 1, but you can actually start them anywhere.

Examples of comments

         ! This is a whole comment line.
           A = B + C       ! This is an end-of-the-line comment.


FORTRAN statements may begin anywhere on a line, so FORTRAN is column-insensitive. A line may be up to 132 characters long. If a statement needs to be longer than this, we can continue it on the next line by putting an ampersand (&) at the end of the first line.

Example of continuation

         Variable1 = (SomeVariable + SomeOtherVariable) * &
                     WhateverVariable

We can have more than one statement on a line if we use a semicolon (;) to separate them.


Names we invent to use in a FORTRAN programs may be up to 31 characters long, using letters (A-Z, a-z), digits (0-9) and the underscore character (_). Names may not begin with a digit or an underscore.

Examples of good and bad names   

         Distance                           ! Valid
         Speed                              ! Valid
         H14                                ! Valid
         Miles_Per_Hour                     ! Valid

         3_Days                             ! Not valid
         A_very_very_long_ugly_boring_name  ! Not valid
         My$alary                           ! Not valid

FORTRAN is case-insensitive, so (for example) the names "THIS", "this" and "This" are all equivalent.

There are various other characters which are also used in FORTRAN for other purposes.


Some FORTRAN statements have statement labels starting in column 1. This is simply a whole number of up to 5 digits (00000 to 99999). We will see this for FORMAT statements and probably for nothing else.


Important note: The above information is for the version of FORTRAN we are using, FORTRAN 90/95. Older versions of FORTRAN such as FORTRAN 77 have different and greater limitations: names restricted to 6 characters, a much more frequent use of statement labels, etc.