next up previous contents index
Next: Program Units Up: Statements and Lines Previous: Comment Lines

Statement Labels

    A label can be attached to any statement. There are three reasons for using labels:

Example:

 
*Read numbers from input file until it ends, add them up. 
      SUM = 0.0 
100   READ(UNIT=IN, FMT=200, END=9999) VALUE 
200   FORMAT(F20.0) 
      SUM = SUM + VALUE 
      GO TO 100 
9999  WRITE(UNIT=*, FMT=*)'SUM of values is', SUM
Each label has the form of an unsigned integer in the range 1 to 99999. Blanks and leading zeros are ignored. The numerical value is irrelevant and cannot be used in a calculation at all. The label must appear in columns 1 to 5 of the initial line of the statement. In continuation lines the label field must be blank.

A label must be unique within a program unit but labels in different program units are quite independent. Although any statement may be labelled, it only makes sense to attach a label to a FORMAT statement or an executable statement, since there is no way of using a label on any other type of statement.

Statement labels are unsatisfactory because nearly all of them mark a point to which control could be transferred from elsewhere in the program unit. This makes it much harder to understand a program with many labelled statements. Unfortunately at present one cannot avoid using labels altogether in Fortran. If labels are used at all they should appear in ascending order and preferably in steps of 10 or 100 to allow for changes. Labels do not have to be right-justified in the label field.


next up previous contents index
Next: Program Units Up: Statements and Lines Previous: Comment Lines
Helen Rowlands
8/27/1998