HP 3000 Manuals

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


HP Business BASIC/XL Reference Manual

PRINT 

The PRINT statement can output several values.  It can use output
functions to output control characters.  The PRINT statement is similar
to the DISP statement.  The PRINT statement uses the output device
specified by the most recently executed SEND OUTPUT TO statement, and the
DISP statement uses the standard list device.  If the most recently
executed SEND OUTPUT TO statement specifies the standard list device, or
if the program has not executed a SEND OUTPUT TO statement, then the
PRINT statement is equivalent to the DISP statement.  The PRINT statement
can also transfer the value of one or more variables to a data file.

Syntax 

                         [,]
PRINT [output_item_list] [;] PRINT #fnum [, rnum [, wnum]];

output_item_list 

Parameters 

fnum             The file number that HP Business BASIC/XL uses to
                 identify the file.  It is a numeric expression that
                 evaluates to a positive short integer.

rnum             Record number, a numeric expression.  If a file I/O
                 statement specifies rnum, it is direct; otherwise, it is
                 sequential.

wnum             Word number, a numeric expression.  If a file I/O
                 statement specifies wnum, it is direct word.  This is
                 only allowed with BASIC DATA files.

                                   [{[,]...}            ]
output_item_     [,]...output_item [{;     } output_item]...
list 

output_item      One of the following:

                 num_expr 

                 str_expr 

                 ,                A separator that prints each new item
                                  in a separate output field.

                 ;                A separator that prints each new item
                                  right next to the previous item.

                 array_name(*)    Array reference.  See "Array References
                                  in Display List" in chapter 6 for more
                                  information.

                                  {PAGE            }
                                  {{CTL}           }
                 output_function  {{LIN}           }
                                  {{SPA} (num_expr)}
                                  {{TAB}           }

                                  See "Output Functions in Display List"
                                  in chapter 6 for more information.

                 FOR_clause       (FOR num_var=num_expr1 TO num_expr2 
                                  [STEP num_expr3], d_list)

                                  See the section that follows, "FOR
                                  Clause in Display List", for more
                                  information.

Examples 

Below are several examples of the PRINT statement.

     200 PRINT
     210 PRINT,
     220 PRINT;
     230 PRINT X,X+Y;A$,LWC$(A$+B$);P(*),Q$(*);PAGE,TAB(10+X);
     240 PRINT Z(*), (FOR I=1 TO 10, Z(I); 2*Z(I); I*Z(I)), D$
     250 PRINT X,B$,C(*),D$(*),
     260 PRINT A,,B
     270 PRINT "THE ANSWER IS: "; Final_total

The PRINT statement evaluates the expressions in the display list from
left to right, and displays their values on the appropriate output
device.  It displays numeric values in the current numeric output format
(see "Numeric Format Statements").

A PRINT statement without a display list prints a carriage return and a
line feed (a CRLF) on the output file or device.

The following examples show the PRINT statement used with data files.

     100 PRINT #1; A,B,C
     110 PRINT #2,5; D$,E
     120 PRINT #3,7,4; F(),G$(*,*)
     130 PRINT #4; N,M,(FOR I=1 TO 5, A(I,I), B$(I,I))

The PRINT statement writes BASIC DATA, binary, and ASCII files
differently; see Table 4-12.

          Table 4-12.  Effect of File Type on PRINT Statement 

-------------------------------------------------------------------------------------------------
|                   |                           |                       |                       |
|                   |        BASIC DATA         |        Binary         |         ASCII         |
|                   |                           |                       |                       |
-------------------------------------------------------------------------------------------------
|                   |                           |                       |                       |
| Sequential Write  | Record indicated by       | Record indicated by   | Record indicated by   |
| Starts at         | record pointer.           | record pointer.       | record pointer.       |
|                   |                           |                       |                       |
-------------------------------------------------------------------------------------------------
|                   |                           |                       |                       |
| And Writes        | As many records as needed | As many records as    | As many records as    |
|                   | for output list.          | needed for output     | needed for output     |
|                   |                           | list.                 | list.                 |
|                   |                           |                       |                       |
-------------------------------------------------------------------------------------------------
|                   |                           |                       |                       |
| Direct Write      | Record rnum.              | Record rnum.          | Record rnum.          |
| Starts at         |                           |                       |                       |
|                   |                           |                       |                       |
-------------------------------------------------------------------------------------------------
|                   |                           |                       |                       |
| And Writes        | One record.  Error occurs | One record.  Error    | One record.  Error    |
|                   | if record cannot          | occurs if record      | occurs if record      |
|                   | accommodate output list.  | cannot accommodate    | cannot accommodate    |
|                   |                           | output list.          | output list.          |
|                   |                           |                       |                       |
-------------------------------------------------------------------------------------------------
|                   |                           |                       |                       |
| Direct Word Write | Word wnum of record rnum. | Not allowed.          | Not allowed.          |
| Starts at         |                           |                       |                       |
|                   |                           |                       |                       |
-------------------------------------------------------------------------------------------------
|                   |                           |                       |                       |
| And Writes.       | As many records as needed | Not allowed.          | Not allowed.          |
|                   | for output list.          |                       |                       |
|                   |                           |                       |                       |
-------------------------------------------------------------------------------------------------


NOTE Data that is written to an ASCII file by a PRINT statement cannot be read accurately by a READ statement unless the PRINT statement writes commas between data items on the file. For example, the statement: 200 READ #1; A,B,C$,D$ can read the data written by the statement: 100 PRINT #1; 123, ",", 456, ",abc", ",def" but not by the statement: 110 PRINT #1; 123,456,"abc","def"
FOR Clause in Display List The display list of a PRINT statement 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], output_item_list) Parameters num_var A numeric variable assigned the sequence of values: num_expr1, num_expr1+num_expr3, num_expr1+(2*num_expr3), etc. The DISP or PRINT statement prints the values of the elements of d_list for each value 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 to which num_var is compared before the DISP or PRINT statement prints a value. If num_expr3 is positive and num_var > num_expr2, the loop execution is terminated. If num_expr3 is negative and num_var < num_expr2, the loop execution is terminated. num_expr3 Amount by which num_var increases at the end of the loop. The default value is 1 if the step option is not specified. output_item_ Same as d_list in DISP or PRINT statement syntax. list Examples PRINT "Values for A are: ",(FOR I=1 TO 4, A(I);),,,"X Value: ",X If each variable is assigned the following values prior to execution of line 20: A(1) = 10 A(2) = 20 A(3) = 30 A(4) = 40 X = 50 The output generated by line 20 is: Values for A are: 10 20 30 40 X Value: 50 Display list FOR clauses can be nested. 20 PRINT (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 variable value that the above statement prints. -------------------------------------------------------------------------------------------------- | | | | | | Value of I | Value of J | Value of K | Variable Printed | | | | | | -------------------------------------------------------------------------------------------------- | | | | | | 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