SPL to HP C/XL Migration Guide (30231-90001)

6-8
Table 6-12. CASE Statement Examples
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| | |
| CASE N OF | switch (N) |
| BEGIN | { |
| A:=100; <<case 0, N=0>> | case 0: A=100; /* N==0 */ |
| ; <<case 1, N=1>> | break; |
| BEGIN <<case 2, N=2>> | case 1: break; /* N==1 */ |
| A:=90; | case 2: A=90; /* N==2 */ |
| B:=1; | B=1; |
| END; | break; |
| B:=100; <<case 3, N=3>> | case 3: B=100; /* N==3 */ |
| END; | break; |
| | } |
| | |
---------------------------------------------------------------------------------------------
| | |
| Case 1 is a null statement. It is required | Case 1 could be omitted entirely, since an |
| to fill out the range of values for N, even | index not represented by a case label |
| if N would never equal 1. | terminates the switch. |
| | |
| | To emulate the SPL operation, each case |
| | ends with a break statement to terminate |
| | the switch. |
| | |
| | Note that case 2 does not require braces |
| | around the two statements, although they |
| | could be used to clarify the BEGIN-END |
| | translation. |
| | |
---------------------------------------------------------------------------------------------
Again, please note the following:
In SPL, after each "case" of a CASE statement is executed, there is an
automatic transfer to the end of the CASE statement. In HP C/XL,
execution by default "falls through" to the next case. The break
statement causes control to transfer to the statement following the
switch statement, emulating SPL's action.
This and other features of the HP C/XL switch statement may afford
opportunities to simplify older SPL algorithms once the code has been
implemented in HP C/XL.
In the HP C/XL switch statement, if you include a case labelled default,
invalid indexes will transfer to this label. Using a default label is
good programming practice.
The HP C/XL case labels are simply entries into a series of statements.
They may occur in any order and there may be gaps in the numeric
sequence.