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

4-: 55
end of the multi-line function, but for program documentation purposes it
is a good idea to include the FNEND.
Example
10 READ A
25 DATA 3
20 C= FNMath(A) !Calls the function.
30 PRINT C
99 END
100 DEF FNMath(X) !Start of the function.
110 Y=X*2
120 RETURN Y !Return from the function.
999 FNEND !Indicates the end of the function.
FOR
The FOR and NEXT statements define a loop that is repeated until the
value of the loop control variable is greater than or less than a
specified value. The value of the loop control variable can increase or
decrease.
Syntax
FOR
num_var
=
num_expr1
TO
num_expr2
[STEP
num_expr3
] [
stmt
]...
NEXT
num_var
Parameters
num_var
The numeric loop control variable that assumes the
values
num_expr1
,
num_expr1
+
num_expr3
,
num_expr1
+(2*
num_expr3
), etc. on successive executions
of the loop body. The loop body executes once for each
value that is less than or equal to
num_expr2
(if
num_expr3
is positive) or greater than or equal to
num_expr2
(if
num_expr3
is negative).
The
num_var
in the FOR and NEXT statements must be the
same.
num_expr1
The initial value that
num_var
is assigned.
num_expr2
Value that
num_var
is compared to before the loop body
is executed. If
num_expr3
is positive and
num_var
>
num_expr2
, the loop body is not executed. Similarly, if
num_expr3
is negative and
num_var < num_expr2,
the loop
body is not executed.
num_expr3
Amount that
num_var
is incremented by (if
num_expr2
is
positive) or decremented (if
num_expr2
is negative)
following execution of the statements in the loop body.
stmt
If
num_expr2
is positive, this statement or statements
executes each time
num_var
<=
num_expr2
. If
num_var
is
negative, this statement executes each time
num_var
>=
num_expr2
. These statements constitute the loop body.
Examples
10 FOR I=2 TO 10 STEP 2 !This will loop 5 times.
20 PRINT "I=",I !Values are: 2,4,6,8,10
30 PRINT "I+I=",I+I !Values are: 4,8,12,16,20
40 PRINT "I*I=",I*I !Values are: 4,16,36,64,100
50 NEXT I
10 FOR J=4 TO 1 STEP -1 !This will loop 4 times
20 PRINT J !Values 4,3,2,1
30 NEXT J
100 FOR K=1 TO 20 !This will loop 20 times
110 PRINT K !Values 1,2,3,...,19,20
120 NEXT K