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