WHILE [ EDIT/3000:Reference Manual ] MPE/iX 5.0 Documentation
EDIT/3000:Reference Manual
WHILE
4-1. WHILE COMMAND
4-2. PURPOSE
The WHILE command causes EDIT/3000 to repeat the two commands following
subject to tbese conditions:
1. While a WORK file condition specified in the EDIT/3000 command
immediately following the WHILE command can be met (the flag is
true).
2. Until the number of iterations specified by the SET TIME = limit
command has been met (the default is 50 iterations). See Section
III, paragraph 3-92 for a discussion of the SET command.
For example, the WHILE block
WHILE
FIND "EDIT/3000"
LIST *
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,
WHILE FLAG
FIND "EDIT/3000" (+8)
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.
NOTE The character position (+8) is necessary in the FIND command to
position the pointer to the last character in the string.
Otherwise, EDIT/3000 would find the string, the pointer would be
located at the first character of the string, and the next
iteration would find the same string. In the above example, 1 can
be used instead of 8.
4-3. FORM
The form of the WHILE command is
WHILE [FLAG]
4-4. DESCRIPTION
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.)
NOTE When a soft error does occur, only a NOT, a YES, an OR or an END
command can be executed during the WHILE or USE modes. See
paragraph 4-13 for a discussion of the NOT command and paragraph
4-25 for a discussion of the YES command.
4-5. LIMITATIONS
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.
4-6. EXAMPLES
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.
/S SHORT;T EDIT3;L ALL
1 1-2. WHAT IS EDIT/3000?
2
3 EDIT/3000 IS A SUBSYSTEM OF THE HP 3000
4 MULTI-POGRAMMING EXECUTIVE OPERATING SYSTEM
5 (MPE/3000) THAT IS USED TO CREATE AND
6 MANIPULATE ASCII FILES.
7
8 CHARACTERS, STRINGS OF CHARACTERS, 0R ENTIRE
9 LINES; OF CHARACTER CAN BE INSERTED, DELETED,
10 REPLACED, MODIFIED, SEARCHED FOR, AND OTHERWISE
11 MANIPULATED BY USING EDIT/3000 COMMANDS.
12
13 1-2. EDIT/3000 FEATURES
14
15 WITH EDIT/3000, IT IS POSSIBLE TO
16
17 CREATE AND BUILD A NEW FILE (CALLED A WORK FILE)
18 BY ENTERING COMMANDS AND LINES OF TEXT FROM THE
19 STANDARD INPUT DEVICE OR FROM A SPECIAL DISC FILE
20 CALLED THE HOLD FILE.
21
22 SAVE THE WORK FILE INTO A PERMANENT FILE CALLED
23 THE TEXT FILE.
24
25 CALL THE TEXT FILE BACK INTO THE WORK FILE FOR
26 FURTHER ADDITIONS AND/OR EDITING.
27
28 CHANGE ALL OCCURENCES OF A CHARACTER STRING WITH
29 ONE COMMAND.
30
31 DELETE CHARACTERS AND LINES FROM THE WORK FILE.
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
*21* STRING NOT FOUND BEFORE LIMIT AT DEPTH 2
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.
/FINDQ FIRST
/WHILE
/ FIND "EDIT/3000"
/ LIST*
/FIND "EDIT/3000"
1 1-2. WHAT IS EDIT/3000?
^ (15)
/LIST*
1 1-2. WHAT IS EDIT/3000?
/FIND "EDIT/3000"
3 EDIT/3000 IS A SUBSYSTEM OF THE HP 3000
^ (1 )
/LIST*
3 EDIT/3000 IS A SUBSYSTEM OF THE HP 3000
/FIND "EDIT/3000"
11 MANIPULATED BY USING EDIT/3000 COMMANDS.
^ (22 )
/LIST*
11 MANIPULATED BY USING EDIT/3000 COMMANDS.
/FIND "EDIT/3000"
13 1-2. EDIT/3000 FEATURES
^ (7 )
/LIST*
13 1-2. EDIT/3000 FEATURES
/FIND "EDIT/3000"
15 WITH EDIT/3000. IT IS POSSIBLE TO
^ (6 )
/LIST*
15 WITH EDIT/3000, IT IS POSSIBLE TO
/FIND "EDIT/3000"
*21*STRING NOT FOUND BEFORE LIMIT
AT DEPTH 2
-/LIST*
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.
/FINDQ FIRST
/WHILE FLAG
/ FIND "EDIT/3000"(+8)
1 1-2. WHAT IS EDIT/3000?
^ (23 )
3 EDIT/3000 IS A SUBSYSTEM OF THE HP 3000
^ (9 )
11 MANIPULATED BY USING EDIT/3000 COMMANDS.
^ (30 )
13 1-2. EDIT/3000 FEATURES
^ (15 )
15 WITH EDIT/3000, IT IS POSSIBLE TO
^ (14 )
*21*STRING NOT FOUND BEFORE LIMIT
AT DEPTH 2
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.
/FINDQ FIRST
/WHILE FLAG
/ FIND "EDIT/3000"
/FIND "EDIT/3000"
1 1-2. WHAT IS EDIT/3000?
^ (15 )
/FIND "EDIT/3000"
1 1-2. WHAT IS EDIT/3000?
^ (15 )
/FIND "EDIT/3000"
1 1-2. WHAT IS EDIT/3000?
^ (15 )
/FIND "EDIT/3000"
1 1-2. WHAT IS EDIT/3000?
*21*STRING NOT FOUND BEFORE LIMIT
AT DEPTH 2
MPE/iX 5.0 Documentation