Download STARTUP HANDBOOK

Transcript
18.4.2 SELECT CASE
Execute the statement block associated with the matching condition out of multiple
conditions.
Syntax
SELECT_CASE <expression>
CASE_<item>
: 'Executes the statements if the value of <expression> matches
'<item> in the CASE sentence
[CASE_ELSE]
: 'Executes the statements if the value of <expression> matches
'<item> in all of the CASE sentences
END_SELECT
Description
In a SELECT_CASE statement, <expression> is placed after the SELECT_CASE. If the
value of <expression> matches <item> of the CASE statement, the statement block
following the CASE and preceding the next CASE is executed.
If the value of <expression> does not match <item> of any CASE statements, the
statement block following the CASE and preceding the next CASE is executed.
Example
Ex.) If the value of I1 matches each condition, the corresponding statements are executed.
I1 = 1
YES
Call Pro1
NO
I1 =
3, 5, 7
YES
Call Pro2
NO
I1 =
8 to11
NO
YES
I1 <= 15
NO
I2 = 10
YES
I3 = 5
I2 = 10
Call Pro4
Call Pro3
SELECT CASE I1
CASE 1
CALL PRO1
CASE 3, 5, 7
CALL PRO2
CASE 8 to 11
I2 = 10
I3 = 5
CASE IS <= 15
I2 = 10
CALL PRO3
CASE ELSE
CALL PRO4
END SELECT
'If I1 is 1
'If I1 is 3, 5, or 7
'IF I1 is 8 to 11 (For specifying the range, "** to **" is used.)
'If I1 is 15 or less
'(Comparison format: IS<comparison operator><compared value>)
'If I1 does not match any condition above
18-6