CHOOSE CASE
Description
A control structure that directs program execution based on
the value of a test expression (usually a variable).
Syntax
1 |
CHOOSE CASE <span>testexpression</span><br>CASE <span>expressionlist</span><span><br> statementblock<br></span>{ CASE <span>expressionlist</span><span><br> statementblock <br></span>. . .<br>CASE <span>expressionlist</span> <br> <span>statementblock</span> } <br>CASE ELSE<br> <span>statementblock</span> } <br>END CHOOSE |
Parameter |
Description |
---|---|
testexpression |
The expression on which you want to base |
expressionlist |
One of the following expressions:
|
statementblock |
The block of statements you want PowerBuilder |
Usage
At least one CASE clause is required. You
must end a CHOOSE CASE control structure
with END CHOOSE.
If testexpression at the beginning of
the CHOOSE CASE statement
matches a value in expressionlist for a CASE clause,
the statements immediately following the CASE clause
are executed. Control then passes to the first statement after the END CHOOSE clause.
If multiple CASE expressions exist, then testexpression is
compared to each expressionlist until a match
is found or the CASE ELSE or END CHOOSE is encountered.
If there is a CASE ELSE clause and the
test value does not match any of the expressions, statementblock in
the CASE ELSE clause is executed. If no CASE ELSE clause
exists and a match is not found, the first statement after the END CHOOSE clause
is executed.
Examples
These statements provide different processing based on the
value of the variable Weight:
1 |
CHOOSE CASE Weight |
1 |
CASE IS<16 |
1 |
Postage=Weight*0.30 |
1 |
Method="USPS" |
1 |
CASE 16 to 48 |
1 |
Postage=4.50 |
1 |
Method="UPS" |
1 |
CASE ELSE |
1 |
Postage=25.00 |
1 |
Method="FedEx" |
1 |
END CHOOSE |
These statements convert the text in a SingleLineEdit control
to a real value and provide different processing based on its value:
1 |
CHOOSE CASE Real(sle_real.Text) |
1 |
CASE is < 10.99999 |
1 |
sle_message.Text = "Real Case < 10.99999" |
1 |
CASE 11.00 to 48.99999 |
1 |
sle_message.Text = "Real Case 11 to 48.9999 |
1 |
CASE is > 48.9999 |
1 |
sle_message.Text = "Real Case > 48.9999" |
1 |
CASE ELSE |
1 |
sle_message.Text = "Cannot evaluate!" |
1 |
END CHOOSE |