|
|
EDIT/3000 Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 4 EDIT/3000 ADVANCED COMMANDSWHILE |
|
The WHILE command causes EDIT/3000 to repeat the two commands following subject to these conditions:
For example, the WHILE block
will cause EDIT/3000 to search forward in the WORK file from the current location of the pointer, find the string "EDIT/3000", and list the line containing the string. Once the line has been listed, the pointer is located at the first position of the next line and EDIT/3000 will search forward again for another occurrence of "EDIT/3000". When the end of the WORK file is reached, the condition specified in the first command (the flag command) will fail ("EDIT/3000" can no longer be located) and the WHILE block will terminate execution. (If the number of iterations specified in a SET command is reached before the end of the WORK file, execution will terminate also.) If FLAG is used in the WHILE command, EDIT/3000 will repeat a single command (the command following the WHILE command) until the flag is set to false or until the number of iterations allowed by the SET TIME option in effect is reached. For example,
will find the string "EDIT/3000", position the pointer to the last character in the string (number of characters in string -1) and search forward from there for another occurrence of the same string. When the end of the WORK file is reached, the flag will be set to false and the iterations will terminate.
As long as the condition specified in the first command following a WHILE command can be met, EDIT/3000 sets a flag true and the commands in the WHILE block continue to execute. When the condition specified in the first command cannot be met, EDIT/3000 sets the flag false, execution of the commands in the WHILE block terminates, "soft" error message is displayed. ("soft" error results in an error message but does not terminate EDIT/3000 operation; a "hard" error results in an error message and terminates EDIT/3000 operation. See Section V for a discussion of errors and error messages.)
In a WHILE block, a command may be a basic command or a set of basic commands preceded by a BEGIN command and terminated by an END command. (The BEGIN-END pair enclosing other commands comprises a compound command.) The commands in a WHILE block will execute only as long as the SET TIME = limit option in effect is not exceeded, even if the flag remains true. The default limit is 50 iterations. (If the flag is set to false by EDIT/3000, of course, execution will terminate before the SET TIME value is reached.) The number of BEGIN-END pairs allowed in a WHILE block is determined by the SET DEPTH = limit command. The default limit is 10. If the SET SHORT command is used, display of WHILE block commands during execution is inhibited. If data is embedded in a WHILE block (using SET BATCH), it will be treated as if it were a command; slashes, numbers, and preceding blanks are removed. Two examples of the WHILE command are provided. See paragraph 4-7,"BEGIN-END COMMAND," para- graph 4-13, "NOT COMMAND," paragraph 4-19, "OR COMMAND," and paragraph 4-25, "YES COMMAND" for examples of more complex WHILE blocks which use BEGIN-END pairs, and the NOT, OR, and YES commands. The WORK file is shown below.
In the following example, EDIT/3000 searches forward from the first position of the first line, finds the string "EDIT/3000" in line 1, and lists it. EDIT/3000 then searches forward again and finds and lists the string in lines 3, 11, 13, and 15. The string is not found again before the end of the WORK file is reached and the condition specified in the FIND "EDIT/3000" command fails. EDIT/3000 sets the flag false and prints the error message
Note that after the WHILE command is entered in a session, EDIT/3000 displays the / prompt character, then indents three positions for the next command. This is depth 2.
The next example illustrates the use of the WHILE FLAG command. The WHILE FLAG command causes the next command (instead of the next two commands) to be repeated until the condition specified in the command fails and the flag is set to false by EDIT/3000. The command following WHILE FLAG (FIND "EDIT/3000"(+8)) searches forward, finds the string in line 1, and lists it, The pointer is set to the last character of the string because of the (+8) character position parameter. (To find the last character in a string, the character position parameter must be set equal to number of characters in string &―;1.) The string is found and listed again in lines 3, 11, 13, and 15.
The following example illustrates a FIND command in a WHILE block that does not use the character position parameter to position the pointer to the last character in the string being searched for. EDIT/3000 positions the pointer to the first character in the string. Thus, subsequent iterations of the FIND command locate the same occurrence of the string because the pointer location is not changed. The iterations were terminated by typing CONTROL Y.
|
|