Which of the following is correct syntax for CASE statement?

Which of the following is correct syntax for CASE statement?
A.
Code:
    CASE expression IS
     WHEN choice_1 <=
     Sequential_statements;
     WHEN choice_2 <=
     Sequential_statements;
     ….
    WHEN OTHERS <=
    Sequential_statements;
    END CASE;
B.
Code:
    CASE expression IS
     WHEN choice_1 =>
     Sequential_statements;
     WHEN choice_2 =>
     Sequential_statements;
     ….
    WHEN OTHERS =>
    Sequential_statements;
    END CASE;
C.
Code:
    CASE expression IS
     IF choice_1 <=
     Sequential_statements;
     ELSIF choice_2 <=
     Sequential_statements;
     ….
    ELSIF OTHERS <=
    Sequential_statements;
    END CASE;
D.
Code:
    CASE expression IS
     IF choice_1 =>
     Sequential_statements;
     ELSIF choice_2 =>
     Sequential_statements;
     ….
    ELSIF OTHERS =>
    Sequential_statements;
    END CASE;
 
Answer: b
Explanation: The CASE statement is started with the keyword CASE followed by any identifier or expression and the IS. The expression is solved to get the value and the result of expression is matched with the choices and when it is matched, the corresponding sequential statements are executed. If the value doesn’t match any of the choices, then the statements under OTHERS are executed. It may be noted that the choices are followed by the operator => but not <=.
 

Tìm kiếm

Back
Top