Alternative statement analyses the problem into two cases. Case analysis statement generalizes it to multiple cases. Case analysis splits the problem into an exhaustive set of disjoint cases. For each case, the problem is solved independently. If Cl, C2, and C3 are conditions, and S1, S2, S3 and S4 are statements, a 4 – case analysis statement has the form,
1. case C1
2. S1
3. case C2
4. S2
5. case C3
6. S3
7. else
8. S4
The conditions C1, C2, and C3 are evaluated in turn. For the first condition that evaluates to true, the corresponding sttement is executed, and the case analysis statement ends. If none of the conditions evaluates to true, then the default case S4 is executed.
1. The cases are exhaustive: at least one of the cases is true. If all conditions are false, the default case is true.
2. The cases are disjoint: only one of the cases is true. Though it is possible for more than one condition to be true, the case analysis always executes only one case, the first one that is true. If the three conditions are disjoint, then the four cases are (1) C1, (2) C2, (3) C3, (4) (not C1) and (not C2) and (not C3).