Pascal - Case Else Statement
- Details
- Category: Chapter 2
- Published: Sunday, 14 April 2013 14:27
- Written by Sternas Stefanos
- Hits: 24362
The case-else statement uses an else term after the case labels, just like an if-then-else construct.
1. Syntax:
The syntax for the case-else statement is:
case(expression) of L1 : S1; L2 : S2; ... ... Ln:Sn; else Sm; end;
2. Flow Diagram:
3. Example:
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 following result:
You really did not study right! Your grade is F