HP 3000 Manuals

WHILE [ HP Transact Reference Manual ] MPE/iX 5.0 Documentation


HP Transact Reference Manual

WHILE 

Repeatedly tests a condition clause and executes a simple or compound
statement while the condition is true.

Syntax 

WHILE condition-clause statement;

WHILE causes Transact to test a condition-clause.  The condition clause
includes one or more conditions, each made up of a test-variable, a
relational-operator, and one or more values; multiple conditions are
joined by AND or OR. If the result of that test is true, then the
statement following the condition is executed.  Then the condition clause
is tested again and the process repeated while the result of the test is
true.  When the result of the test is false, control passes to the
statement following the WHILE statement.

Statement Parts 

condition-    One or more conditions, connected by AND or OR, where
clause 

              AND           A logical conjunction.  The condition clause
                            is true if all of the conditions are true; it
                            is false if one of the conditions is false.

              OR            A logical inclusive OR. The condition clause
                            is true if any of the conditions is true; it
                            is false if all of the conditions are false.

              Each condition contains a test-variable,
              relational-operator, and one or more values in the
              following format:

              test-variable relational-operator value [,value]...

test-         Can be one or more of the following:
variable 

              (item-name    The value in the data register that
              [(sub-        corresponds to item-name.  The item-name can
              script)])     be subscripted if an array item is being
                            referenced.  (See "Array Subscripting" in
                            Chapter 3.)

              [arithmetic   An arithmetic expression containing item
              expression]   names and/or constants.  The expression is
                            evaluated before the comparison is made.
                            (See the LET verb for more information.)

                            ____________________________________________ 

                            NOTE  An arithmetic-expression must be
                                  enclosed in square brackets ([ ]).

                            ____________________________________________ 

                            EXCLA-        Current status of the automatic
                            MATION        null response to a prompt set
                                          by a user responding with an
                                          exclamation point (!)  to a
                                          prompt.  (See "Data Entry
                                          Control Characters" in Chapter
                                          5.)  If the null response is
                                          set, the EXCLAMATION test
                                          variable is a positive integer;
                                          if not set, it is zero.  The
                                          default is 0. 

                            FIELD         Current status of FIELD command
                                          qualifier.  If a user qualifies
                                          a command with FIELD, the FIELD
                                          test variable is a positive
                                          integer.  Otherwise, it is a
                                          negative integer.  The default
                                          is < 0.

                            INPUT         The last value input in
                                          response to the INPUT prompt.

                            PRINT         Current status of PRINT or
                                          TPRINT command qualifier.  If a
                                          user qualifies a command with
                                          PRINT, the PRINT test variable
                                          is an integer greater than zero
                                          and less than 10; if a command
                                          is qualified with TPRINT, PRINT
                                          is an integer greater than 10;
                                          if neither qualifier is used,
                                          PRINT is a negative integer.
                                          The default is <0.

                            REPEAT        Current status of REPEAT
                                          command qualifier.  If a user
                                          qualifies a command with
                                          REPEAT, the REPEAT test
                                          variable is a positive integer;
                                          otherwise, REPEAT is a negative
                                          integer.  The default is < 0.

                            SORT          Current status of SORT command
                                          qualifier.  If a user qualifies
                                          a command with SORT, the value
                                          of the SORT test variable is a
                                          positive integer; otherwise
                                          SORT is a negative integer.
                                          The default is < 0.

                            STATUS        The value of a 32-bit integer
                                          register set by the last data
                                          set or file operation, data
                                          entry prompt, or external
                                          procedure call.

relational-   Specifies the relation between the test-variable and the
operator      values.  It can be one of the following:

                              =    equal to

                            <>   not equal to
                            <    less than
                            <=   less than or equal to
                            >    greater than
                            >=   greater than or equal to

value         The value against which the test-variable is compared.  The
              value can be an arithmetic expression, which will be
              evaluated before the comparison is made.  The allowed value
              depends on the test variable, as shown in the comparison
              below.  Alphanumeric strings must be enclosed in quotation
              marks.

              If the test-  The value must be:
              variable 
              is:

              item-name     An alphanumeric string, a numeric value, an
                            arithmetic expression, a reference to a
                            variable as in (item-name), or a class
                            condition as described below.

              [arithmetic   A numeric value, an arithmetic expression, or
              expression]   an expression, or a reference to a variable
                            as in (item-name).

                            INPUT         An alphanumeric string.

                            EXCLA-           A positive or negative
                            MATION           integer, or an expression.
                            FIELD
                            PRINT
                            REPEAT
                            SORT

                            STATUS        A 32-bit integer or expression.

              Alphanumeric strings must be enclosed in quotation marks.
              If more than one value is given, then:

                 *   The relational-operator can be only "=" or "<>".

                 *   When the relational operator is "=", the action is
                     taken if the test-variable is equal to value1 OR
                     value2 OR...valuen.  In other words, a comma in a
                     series of values is interpreted as an OR.

                 *   When the relational operator is "<>", the action is
                     taken if the test-variable is not equal to value1 
                     AND value2 AND...valuen.

                     In other words, a comma in a series of values is
                     interpreted as an AND when the operator is "<>".

              When the test variable is an item-name, the value can be
              one of the following class conditionals, which are used to
              determine whether a string is all numeric or alphabetic.
              The operator can only be "=" or "<>".

              NUMERIC        This class condition includes the ASCII
                             characters 0 through 9 and a single
                             operational leading sign.  Leading and
                             trailing blanks around both the number and
                             sign are ignored.  Decimal points are not
                             allowed in NUMERIC data.  This class test is
                             only valid when the item has the type X, U,
                             9, or Z, or when the item is in the input
                             register.

              ALPHABETIC     This class condition includes all ASCII
                             native language alphabetic characters (upper
                             and lowercase) and space.  This class test
                             is only valid for item names of type X or U.

              ALPHABETIC-    This class condition includes all ASCII
              LOWER          lowercase native language alphabetic
                             characters and space.  This class test is
                             only valid for item names of type X or U.

              ALPHABETIC-    This class condition includes all ASCII
              UPPER          uppercase native language alphabetic
                             characters and space.  This class test is
                             only valid for item names of type X or U.

statement     Any simple or compound Transact statement; a compound
              statement is one or more statements bracketed by a DO/DOEND
              pair.

Order of Evaluation 

When complex conditions are included, the operator precedence is:

   *   Arithmetic expressions are evaluated.
   *   Truth values are established for simple relational conditions.
   *   Truth values are established for simple class conditions.
   *   Multiple value conditions are evaluated.
   *   Truth values are established for complex AND conditions.
   *   Truth values are established for complex OR conditions.

Parentheses can be used to control the order of precedence when
conditional clauses are being evaluated.  In multiple value conditions,
evaluation terminates as soon as a truth value is determined.

Examples 

     WHILE (SUB-TOTAL) >= 0
       DO
        GET(CHAIN) ORDERS;
        .
        .
        .
       LET (SUB-TOTAL)=(SUB-TOTAL) - (OUT-BAL);
       DOEND;

     WHILE (BALANCE) < 0 AND STATUS  0
         DO
           GET(CHAIN) CUST-DETAIL,STATUS;
           LET (BALANCE) = (BALANCE) + (AMOUNT);
         DOEND;

     WHILE (PART-NO-PREFIX) <> (PROTOTYPE),(DEVELOPMENT)
           GET(CHAIN) PART-DETAIL,STATUS;

The next example sorts the entries in data set ORDER-DET in primary
sequence by ORD-NO and in secondary sequence by PROD-NO. As it sorts, it
passes the sorted entries to the PERFORM statements at the label DISPLAY
to be displayed in sorted order.

     SORT-FILE:
        LIST ORD-NO:
             PROD-NO:
             DESCRIPTION:
             QTY-ORD:
             SHIP-DATE:

        FIND(SERIAL) ORDER-DET,
             LIST=(ORD-NO:SHIP-DATE),
             SORT=(ORD-NO,PROD-NO),
             PERFORMDISPLAY;
           .
           .
     DISPLAY:
        DISPLAY "Order List by Product Number", LINE2:
                 ORD-NO, NOHEAD, COL5:
                 PROD-NO, NOHEAD, COL20:
                 QTY-ORD, NOHEAD, COL35:
                 SHIP-DATE, NOHEAD, COL50;



MPE/iX 5.0 Documentation