The case-else statement uses an else term after the case labels, just like an if-then-else construct.
The syntax for the case-else statement is −
case (expression) of L1 : S1; L2 : S2; ... ... Ln: Sn; else Sm; end;
The following example illustrates the concept
program checkCase; var grade: char; begin grade := 'F'; case (grade) of 'A' : writeln('Excellent!' ); 'B', 'C': writeln('Well done' ); 'D' : writeln('You passed' ); else writeln('You really did not study right!' ); end; writeln('Your grade is ', grade ); end.
When the above code is compiled and executed, it produces the following result −
You really did not study right! Your grade is F