SPL to HP C/XL Migration Guide (30231-90001)
6-4
FOR Statement
Table 6-7. FOR Statement
---------------------------------------------------------------------------------------------
|| |
| SPL | HP C/XL Equivalent |
|| |
---------------------------------------------------------------------------------------------
|| |
|
for-statement
:|
for-statement
:|
|| |
| 1. FOR
test-var
:=
init-val
| 1. for (
test-var
=
init-val
;|
| UNTIL
end-val
|
test-var
<=
end-val
;|
|DO
loop-statement
|
test-var
++ ) |
||
loop-statement
|
|| |
| 2. FOR
test-var
:=
init-val
| 2a. for (
test-var
=
init-val
;|
| STEP
step-val
|
test-var
<=
end-val
;|
| UNTIL
end-val
|
test-var
+=
step-val
)|
|DO
loop-statement
|
loop-statement
|
|| |
| | 2b. for (
test-var
=
init-val
;|
||
test-var
>=
end-val
;|
||
test-var
+=
step-val
)|
||
loop-statement
|
|| |
| 3. FOR *
test-var
:=
init-val
| 3. for (
flag
=1,
test-var
=
init-val
;|
| UNTIL
end-val
|
flag
||
test-var
<=
end-val
;|
|DO
loop-statement
|
flag
=0,
test-var
++ ) |
||
loop-statement
|
|| |
| 4. FOR *
test-var
:=
init-val
| 4a. for (
flag
=1,
test-var
=
init-val
;|
| STEP
step-val
|
flag
||
test-var
<=
end-val
;|
| UNTIL
end-val
|
flag
=0,
test-var
+=
step-val
)|
|DO
loop-statement
|
loop-statement
|
|| |
| | 4b. for (
flag
=1,
test-var
=
init-val
;|
||
flag
||
test-var
>=
end-val
;|
||
flag
=0,
test-var
+=
step-val
)|
||
loop-statement
|
|| |
|| |
| | The generic syntax is: |
|| |
| | for (
init-expr
;|
||
test-expr
;|
||
incr-expr
)|
||
statement
|
|| |
---------------------------------------------------------------------------------------------
|| |
|
init-val
,
step-val
, and
end-val
are | In general, the HP C/XL expressions are |
| evaluated and stored.
test-val
is set to | independent, and may even be omitted! The |
|
init-val
. | values in the expressions may be changed in |
| | the body of the for statement. |
|
test-val
is compared to
end-val
.If | |
|
step-val
is positive or omitted, and | The first expression (e.g.,
init-expr
)is |
|
test-val
is less than or equal to
end-val
, | evaluated only once, on initial entry into |
|
loop-statement
is executed. If
step-val
is | the for statement. |
| negative, and
test-val
is greater than or | |
| equal to
end-val
,
loop-statement
is | For each iteration, the second expression |
| executed. If the test fails, the for | (e.g.,
test-expr
) is evaluated. If it is |
| statement terminates. | false, the for statement is terminated. If |
| | it is true, the
loop-statement
is executed, |
| After
loop-statement
is executed,
test-val
| the third expression (e.g.,
incr-expr
)is |
| is incremented by
step-val
or 1, and it is | evaluated, and the for statement iterates. |
| compared with
end-val
as above. | |
|| |
| | In the simplest case,
init-expr
initializes |
||a
test-var
,
test-expr
tests it, and |
||
incr-expr
increments it. |
|| |
---------------------------------------------------------------------------------------------