External loops make it possible to work through @DO procedures repeatedly in full. If only parts of a procedure are to be looped through repeatedly then it is necessary to use internal loops.
External loops are implemented by referencing a loop counter in the @DO procedure. The start value, end value and increment of this counter must be specified when the procedure is called in the @DO statement (see @DO statement "@DO (format 1) - Start EDT procedures from work files "). The loop counter must be a special character and should not conflict with special characters which have a fixed meaning in EDT (e.g. %
or $
). In contrast, the characters !
or |
are suitable. Within the @DO procedure, the loop counter must be used like a line number (not like a line number variable, i.e. it cannot be modified in the procedure).
When the last statement in the @DO procedure is executed, the loop counter is increased or decreased by the specified increment and compared with the end value. If the comparison value is not greater or lower than the end value accordingly, the procedure is run again with the modified loop counter value. If the last statement in the @DO procedure is not executed, for example because the procedure has been exited with @RETURN, the procedure is not looped through again but is interrupted, perhaps before the specified end value is reached. It may therefore be necessary to write an artificial (empty) final statement (see @CONTINUE statement).
The special character representing the loop counter may be present, when the @DO statement is entered, in a character set other than that used in the called procedure. If necessary, it is converted in accordance with the same rules as the literals which may occur in other EDT statements (see section “Character sets”).
External loops can be replaced by internal loops. In an external loop, alongside the start and end value it is only possible to specify a fixed positive or negative increment. In an internal loop, it is possible to specify a variable increment, for example via a line number variable.
Example of an external loop
@PROC 3 @DELETE @ @COLUMN 10 ON ! INSERT !:27-36: @END
The above statement sequence constructs a @DO procedure containing the single statement @COLUMN... in work file 3.
If this @DO procedure is started with @DO 3, !=11,15
, then the values 11,12,13,14
and 15
are used sequentially for the loop counter !
(the implicit increment is 1
). In these lines, the content of the relevant line (columns 27-36
) is inserted again at column 10
.
If this procedure is applied to a work file with a smaller increment (for example 0.1
) then some lines may be ignored. If all the lines are to be taken into account independently of the increment, an internal loop should be used (see example below).
Example of an internal loop
@PROC 4 -------------------------------------------------------------- (01) @DELETE @RESET @1.00 @ @IF ERRORS : @G0TO 2 ----------------------------------------------- (02) @ @IF #L10 > 15 @GOTO 2 ---------------------------------------------- (03) @ @COLUMN 10 ON #L10 INSERT #L10:27-36: ------------------------------ (04) @ @SET #L10 = #L10 + 1L ---------------------------------------------- (05) @ @G0T0 1 ------------------------------------------------------------ (06) @2.00 @ @CONTINUE @END.... @SET #L10 = 11 ------------------------------------------------------- (07) @DO 4
(01) | A @DO procedure is constructed in work file 4. |
(02) | The procedure should be aborted if EDT errors occur. |
(03) | If loop counter |
(04) | The content of the corresponding line in column |
(05) | The line number is set to the next existing line number. Specifying the value |
(06) | Processing branches to the start of the loop. |
(07) | The start value of the loop counter is set outside of the @DO procedure and the procedure is then called. |
Note
Line 11.00
must exist in the file that is to be processed and the last line in the file to be processed should be greater than 15.00
, otherwise the procedure is aborted with an error message.