Choosing bethween IF and CASE statementsΒΆ
When deciding to use either IF
or CASE
statements, you should take following points into consideration:
- A simple
CASE
statement is much more readable than theIF
statement when you compare a single expression against a range of unique values. In addition, the simpleCASE
statement is more efficient than theIF
statement. - When you check complex expressions based on multiple values, the
IF
statement is easier to understand. - If you choose to use the
CASE
statement, you have to make sure that at least one ofCASE
conditions is matched. Otherwise, you need to define an error handler to catch the error. Recall that you do not have to do this in theIF
statement.