The text read off it
[page 50]
sections.)
Any procedure, i.e., any sentence or section, that is referred to by a DO command must be what is known technically as a "closed" or "linked" subroutine. That is, it must be entered only through the use of a DO command, and not by any other means such as transfer of control to a sentence within the procedure or through the normal passage of control to the first sentence of the procedure. It should be noted, however, that this rule permits the addressing of a procedure by more than one DO command.
When the DO command takes the first of the two forms shown above, the "procedure.name" subroutine is executed only once and control passes to the sentence or clause following the DO.
For example, the programmer might write:
DO CALC.ORDER.POINT.
IF ORDER.POINT IS LESS THAN 2.5 * MONTHLY.USAGE THEN
GO TO . . .
The DO command in this example will cause the CALC.ORDER.POINT procedure (subroutine) to be executed once, whereupon control will pass to the IF ORDER.POINT IS . . . sentence.
With the second form of the command the "procedure.name" procedure is executed the specified number of times. The number of repetitions, n, may be stated as a literal or as a data-name, but in either case the value of n must be a positive integer. To illustrate this form of the DO, suppose that in a payroll program a field called BOND.ACCUM is divided by another field, BOND.DENOM, and the result truncated to an integer in order to determine the number of bonds purchasable. The result might be called NO.OF.BONDS. Then the programmer could write:
DO BOND.ORDER.RTN EXACTLY NO.OF.BONDS TIMES.
This example assumes, of course, that the payroll program contains a procedure called BOND.ORDER.RTN which is used to prepare a file of bond orders.
The DO Command with Indexing
Repetitive execution, or looping, of a procedure based on indexing is provided in the more powerful forms of the DO command. To control a single index and/or provide subscript control of the variables associated with the index, the DO command takes the form:
DO procedure.name FOR index.name = p(q)r
where "index.name" represents a field which has been defined in the data description as an integer. The effect of this DO command (in the object program) is to set the index to the initial value p and transfer control to the first sentence of the named procedure. After the last sentence of the procedure has been reached and executed, control is returned to the DO command which increments the index by the quantity q and causes control to return to the "loop." This process is repeated until the value of the index equals r; at this point, control is no longer returned to the loop but instead passes to the sentence or clause which follows the DO. To state this another way, the command, "DO rtn FOR i = p(q)r" is the equivalent of:
