# 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 = expr 1, expr 2 [, expr 3])

list | Is a list of variables, expressions, or constants (see Simple List Items in I/O Lists ).
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:

- Specify iteration of part of an I/O list

- Transfer part of an array

- Transfer array items in a sequence different from the order of subscript progression

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.

Consider the following:

            INTEGER mydata(25)
            READ (10, 9000) (mydata(I), I=6,10,1)
      9000  FORMAT (5I3)

In this example, the iolist specifies to put the input data into elements 6 through 10 of the array called mydata. The third value in the implied-DO loop, the increment, is optional. If you leave it out, the increment value defaults to 1.

Parent topic: I/O Lists

## See Also

Execution Control
I/O Lists for details on the general rules for I/O lists