HP 3000 Manuals

Creating Processing Loops [ Command Interpreter Access and Variables Programmer's Guide ] MPE/iX 5.0 Documentation


Command Interpreter Access and Variables Programmer's Guide

Creating Processing Loops 

The CI provides a looping structure through the WHILE and ENDWHILE
statements.  Combined with the expression evaluator functions, a series
of statements can be repeated as long as a particular condition exists.
The MENU command file provides a processing loop that continues prompting
for the user's response and selecting the proper subroutine until the
user selects 0 to exit the routine.

     SETVAR CHOICE " "
     WHILE CHOICE <> "0" DO
       ECHO Enter 0 to exit.
       ECHO       1 to review database.
       ECHO       2 to update database.
       INPUT CHOICE,"Which number do you select?",15
       IF CHOICE = "1" THEN
         DBREVIEW
       ELSEIF CHOICE = "2" THEN
         DBUPDATE
       ENDIF
     ENDWHILE

Often an index is set and evaluated for processing elements of an array.
Although the CI does not support data arrays or tables, variable names
can be constructed so that a portion of the name can be incremented to
access several variables in a sequence, similar to array or table
processing.

In the following example, a simulated array of data has been created by
appending sequential numbers to a common variable name.  The variables
range from RM_ARRAY1 to RM_ARRAYn, depending on the number of elements
needed.  In this example, the variable RM_ARRAY0 contains the number of
elements used in the sequence.

Each variable in this example is accessed in turn by concatenating the
common portion of the variable name with an incremented index variable,
creating the sequence of variable names.  The processing loop continues
to access consecutive variables until the index exceeds the value of
RM_ARRAY0.

     SETVAR RM_INDEX 1
     WHILE RM_INDEX <= RM_ARRAY0 DO
       ECHO Purging !"RM_ARRAY!RM_INDEX" now.
       PURGE !"RM_ARRAY!RM_INDEX"
       SETVAR RM_INDEX RM_INDEX+1
     ENDWHILE



MPE/iX 5.0 Documentation