10.2.2.2 Implied-Do Lists in I/O Lists

In a data transfer statement, an implied-do list acts as though it were a part of an I/O statement within a DO loop. It takes the following form:

(list, do-var = expr1, expr2 [, expr3])

list
Is a list of variables, expressions, or constants (see Section 10.2.2.1).

do-var
Is the name of a scalar integer or real variable. The variable must not be one of the input items in list.

expr
Are scalar numeric expressions of type integer or real. They do not all have to be the same type, or the same type as the DO variable.

The implied-do loop is initiated, executed, and terminated in the same way as a DO construct.

The list is the range of the implied-do loop. Items in that list can refer to do-var, but they must not change the value of do-var.

Two nested implied-do lists must not have the same (or an associated) DO variable.

Use an implied-do list to do the following:

If the I/O statement containing an implied-do list terminates abnormally (with an END, EOR, or ERR branch or with an IOSTAT value other than zero), the DO variable becomes undefined.

Examples

The following two output statements are equivalent:

  WRITE (3,200) (A,B,C, I=1,3)            ! An implied-do list

  WRITE (3,200) A,B,C,A,B,C,A,B,C         ! A simple item list
The following example shows nested implied-do lists. Execution of the innermost list is repeated most often:
  WRITE (6,150) ((FORM(K,L), L=1,10), K=1,10,2)
The inner DO loop is executed 10 times for each iteration of the outer loop; the second subscript (L) advances from 1 through 10 for each increment of the first subscript (K). This is the reverse of the normal array element order. Note that K is incremented by 2, so only the odd-numbered rows of the array are output.

In the following example, the entire list of the implied-do list (P(1), Q(1,1), Q(1,2)...,Q(1,10)) are read before I is incremented to 2:

  READ (5,999) (P(I), (Q(I,J), J=1,10), I=1,5)
The following example uses fixed subscripts and subscripts that vary according to the implied-do list:
  READ (3,5555) (BOX(1,J), J=1,10)
Input values are assigned to BOX(1,1) through BOX(1,10), but other elements of the array are not affected.

The following example shows how a DO variable can be output directly:

  WRITE (6,1111) (I, I=1,20)
Integers 1 through 20 are written.

For More Information:


Previous Page Next Page Table of Contents