HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)

4-: 45
FOR Clause in Display List
The display list of a DISP 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 that
num_var
is compared to before the DISP or
PRINT statement prints a value. If
num_var
>
num_expr2
, the loop is not executed.
num_expr3
Amount that
num_var
increases by if
num_expr2
is
positive or decreases if
num_expr2
is negative at end
of the loop. The default value is 1 if the step
option is not specified.
output_item_ list
Same as
d_list
in DISP or PRINT statement syntax.
Examples
The following example shows the use of a FOR clause in the display list.
20 DISP "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 DISP (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) |
|||| |
---------------------------------------------------------------------------------------------