HP 3000 Manuals

INPUT [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

INPUT 

The INPUT statement assigns data values obtained from the terminal or a
file to one or more variables.

Syntax 

         [           [{,}           ]   ]
INPUT[:] [input item [{;} input_item]...] [:]

Parameters 

:                A colon specifies that either data currently in the
                 input buffer should be assigned prior to prompting for
                 input or extra input is saved in the input buffer.

                  *  If a colon precedes the input_items, the INPUT
                     statement assigns values in the input buffer to
                     input_elements, from left to right, before prompting
                     you for input or reading input from a file.  If this
                     colon is not specified, HP Business BASIC/XL empties
                     the input buffer before accepting input values.

                  *  If a colon follows the input_items, the INPUT
                     statement stores unassigned input values that are
                     not required to satisfy assignments to the
                     input_items in the input buffer.

                 {[prompt_option] input_element}
input_item       {for_clause                   }

                 An INPUT statement without input_items puts the program
                 in the input state until you press RETURN, but the
                 values entered are not assigned to any input_elements.

                 {PROMPT str_expr}[,]
prompt_option    {str_lit        }[;]

                 If the prompt is not followed by a separator or a comma,
                 a carriage return is generated and user input begins on
                 the next line.  Semicolons suppress the carriage return
                 and input can be typed on the same line as the prompt.
                 See "INPUT Prompt" in chapter 6 for more information.

input_element    One of the following variables that a value is assigned
                 to:

                      num_var 
                      str_var 
                      array_name([*[,*]...])

                 The last format above has either zero or one asterisk
                 per dimension.  The absence of asterisks specifies any
                 number of dimensions.  Either format is legal, but the
                 format without asterisks is noncompilable.

for_clause       (FOR num_var=num_expr1 TO num_expr2 [STEP num_expr3],
                 input_item [, input_item]...)

                 A for_clause is useful for reading array elements (an
                 array can also be input with the MAT INPUT statement).
                 See "FOR Clause in Input List" for more information.

Examples 

The following examples show several ways to use the INPUT statement.

     INPUT
     INPUT A,B$,C(*)
     INPUT A,B$,C(*):
     INPUT:
     INPUT: A,B$,C(*)
     INPUT: A,B$,C(*):
     INPUT A$ A,B$,C(*)
     INPUT PROMPT D$; X,Y, PROMPT D1$+D2$, Z
     INPUT "Input 2 numbers",X,Y,PROMPT D1$+"A";Z,"Input name",N$:
     INPUT: (FOR I=1 TO 10, W(I), WW(I,I))
     INPUT "Input A and elements of V"; A, (FOR J=1 TO 5, V[J]):

An INPUT statement that begins with a colon assigns the values in the
input buffer before prompting you for input or reading it from a file.

An INPUT statement that ends in a colon stores unassigned input values in
an input buffer.

An INPUT statement that does not begin or end with a colon empties the
input buffer before prompting for input.

FOR Clause in Input List 

An input list can contain a FOR clause.  The FOR clause is similar to the
FOR NEXT construct.

Syntax 

(FOR num_var=num_expr1 TO num_expr2 [STEP num_expr3], input_item 

[,input_item]...)

Parameters 

num_var          Assigned the sequence of values:  num_expr1,
                 num_expr1+num_expr3, num_expr1+(2*num_expr3), etc.  The
                 INPUT statement reads one input value for each value of
                 num_var that is less than num_expr2 (if num_expr3 is
                 positive) or greater than num_expr2 (if num_expr3 is
                 negative).

num_expr1        First value assigned to num_var.

num_expr2        Value that num_var is compared to before the INPUT
                 statement reads a value.  If num_expr3 is positive and
                 num_var > num_expr2, loop execution is terminated.  If
                 num_expr3 is negative and num_var < num_expr2, the loop
                 execution is terminated.

num_expr3        Amount that num_var increases by at the end of the loop.
                 The default = 1.

input_item       Same as input_item in INPUT statement syntax.

Examples 

     10 INPUT "Input 4 numbers: ", (FOR I=1 TO 4, A(I)), "Input X: ", X

If you input the underlined values during execution:

     Input 4 numbers:
     10, 20, 30, 40 
     Input X:
     50 

Following execution of line 10, the values assigned to each variable will
be:

     A(1) = 10
     A(2) = 20
     A(3) = 30
     A(4) = 40
     X    = 50

Input list FOR clauses can be nested.

     20 INPUT (FOR I=1 TO 3, (FOR J=1 TO 2 (FOR K=1 TO 2, B(I,J,K))))

For each combination of values of I, J, and K, the following table shows
the value that the above INPUT state assigns to each variable.

--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|    Value of I     |    Value of J     |    Value of K     |           Variable Read            |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         1         |         1         |         1         |              B(1,1,1)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         1         |         1         |         2         |              B(1,1,2)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         1         |         2         |         1         |              B(1,2,1)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         1         |         2         |         2         |              B(1,2,2)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         2         |         1         |         1         |              B(2,1,1)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         2         |         1         |         2         |              B(2,1,2)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         2         |         2         |         1         |              B(2,2,1)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         2         |         2         |         2         |              B(2,2,2)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         3         |         1         |         1         |              B(3,1,1)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         3         |         1         |         2         |              B(3,1,2)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         3         |         2         |         1         |              B(3,2,1)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------
|                   |                   |                   |                                    |
|         3         |         2         |         2         |              B(3,2,2)              |
|                   |                   |                   |                                    |
--------------------------------------------------------------------------------------------------



MPE/iX 5.0 Documentation