The text read off it
[page 53]
DO MIN.ROUT USING R.RATE, E.RATE, M.RATE GIVING MIN.RATE.
The effect of this DO command is equivalent to the following commands:
MOVE R.RATE TO A.
MOVE E.RATE TO B.
MOVE M.RATE TO C.
DO MIN.ROUT.
MOVE MIN TO MIN.RATE.
Now, in another part of the program, the programmer wishes to compare two ages and a constant value to determine the lowest of the three values. The MIN.ROUT procedure will serve the purpose in this situation as well. This time, however, the programmer writes:
DO MIN.ROUT USING INSURED.AGE, BENEFIC.AGE, 70 GIVING
LOW.AGE.
Again the appropriate data substitutions are made when the DO command is executed. As a result, the two values representing ages will be compared with the literal value 70, and the lowest of the three will become the value of LOW.AGE.
The DO Command with Named END
When a DO command is compiled, the processor places appropriate instructions in the object program to effect transfer of control between the DO and the associated procedure and to perform any indexing operations specified in the DO. For correct functioning of the DO, these control instructions must be executed each time an iteration of the associated procedure is executed. The control instructions are performed following the last program command specified in the procedure. Accordingly, a problem arises in the case of a multi-sentence procedure in which the last program command is executed only under certain conditions, i.e., when the logic of the procedure requires a conditional exit prior to the last program command. The solution to the problem is to name the "END procedure.name" sentence which terminates the procedure and to use this name as an exit point. (Normally the END sentence is not named; this is the only exception to the rule.) This provides the necessary linkage with the control instructions. The following DO command and its associated procedure illustrate this situation:
DO REORDER.RTN FOR PART.NO = 1001(1)1499.
.
.
.
REORDER.RTN. BEGIN SECTION.
IF QTY.ON.HAND(PART.NO) IS GREATER THAN ORDER.POINT
(PART.NO) THEN GO TO EXIT.
SET REORDER.AMT(PART.NO) = ORDER.AMT(PART.NO) -
QTY.ON.HAND(PART.NO).
EXIT. END REORDER.RTN.
In this example the logic of the procedure requires that the current iteration be terminated after the first sentence if the conditional clause is true. Assigning the name EXIT to the END sentence makes it possible to bypass the latter part of the procedure and yet maintain the necessary linkage with the control instructions.
