DO (Do)

Free-Form Syntax (not allowed - use the FOR operation code)
Code Factor 1 Factor 2 Result Field Indicators
DO Starting value Limit value Index value

The DO operation begins a group of operations and indicates the number of times the group will be processed. To indicate the number of times the group of operations is to be processed, specify an index field, a starting value, and a limit value. An associated ENDDO statement marks the end of the group. For further information on DO groups, see Structured Programming Operations.

In factor 1, specify a starting value with zero decimal positions, using a numeric literal, named constant, or field name. If you do not specify factor 1, the starting value is 1.

In factor 2, specify the limit value with zero decimal positions, using a numeric field name, literal, or named constant. If you do not specify factor 2, the limit value is 1.

In the result field, specify a numeric field name that will contain the current index value. The result field must be large enough to contain the limit value plus the increment. If you do not specify an index field, one is generated for internal use. Any value in the index field is replaced by factor 1 when the DO operation begins.

Factor 2 of the associated ENDDO operation specifies the value to be added to the index field. It can be a numeric literal or a numeric field with no decimal positions. If it is blank, the value to be added to the index field is 1.

In addition to the DO operation itself, the conditioning indicators on the DO and ENDDO statements control the DO group. The conditioning indicators on the DO statement control whether or not the DO operation begins. These indicators are checked only once, at the beginning of the DO loop. The conditioning indicators on the associated ENDDO statement control whether or not the DO group is repeated another time. These indicators are checked at the end of each loop.

The DO operation follows these 7 steps:

  1. If the conditioning indicators on the DO statement line are satisfied, the DO operation is processed (step 2). If the indicators are not satisfied, control passes to the next operation to be processed following the associated ENDDO statement (step 7).
  2. The starting value (factor 1) is moved to the index field (result field) when the DO operation begins.
  3. If the index value is greater than the limit value, control passes to the calculation operation following the associated ENDDO statement (step 7). Otherwise, control passes to the first operation after the DO statement (step 4).
  4. Each of the operations in the DO group is processed.
  5. If the conditioning indicators on the ENDDO statement are not satisfied, control passes to the calculation operation following the associated ENDDO statement (step 7). Otherwise, the ENDDO operation is processed (step 6).
  6. The ENDDO operation is processed by adding the increment to the index field. Control passes to step 3. (Note that the conditioning indicators on the DO statement are not tested again (step 1) when control passes to step 3.)
  7. The statement after the ENDDO statement is processed when the conditioning indicators on the DO or ENDDO statements are not satisfied (step 1 or 5), or when the index value is greater than the limit value (step 3).

Remember the following when specifying the DO operation:

See LEAVE (Leave a Do/For Group) and ITER (Iterate) for information on how those operations affect a DO operation.

See FOR (For) for information on performing iterative loops with free-form expressions for the initial, increment, and limit values.

For more information, see Structured Programming Operations.

Figure 305. DO Operation
*...1....+....2....+....3....+....4....+....5....+....6....+....7...+....
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....
 *
 *  The DO group is processed 10 times when indicator 17 is on;
 *  it stops running when the index value in field X, the result
 *  field, is greater than the limit value (10) in factor 2.  When
 *  the DO group stops running, control passes to the operation
 *  immediately following the ENDDO operation.  Because factor 1
 *  in the DO operation is not specified, the starting value is 1.
 *  Because factor 2 of the ENDDO operation is not specified, the
 *  incrementing value is 1.
C
C   17              DO        10            X                 3 0
C                   :
C                   ENDDO
 *
 *  The DO group can be processed 10 times.  The DO group stops
 *  running when the index value in field X is greater than
 *  the limit value (20) in factor 2, or if indicator 50 is not on
 *  when the ENDDO operation is encountered.  When indicator 50
 *  is not on, the ENDDO operation is not processed; therefore,
 *  control passes to the operation following the ENDDO operation.
 *  The starting value of 2 is specified in factor 1 of the DO
 *  operation, and the incrementing value of 2 is specified in
 *  factor 2 of the ENDDO operation.
 *
C     2             DO        20            X                 3 0
C                   :
C                   :
C                   :
C   50              ENDDO     2


[ Top of Page | Previous Page | Next Page | Contents | Index ]