Pascal - Case Else Statement
Advertisements
The case-else statement uses an else term after the case labels, just like an if-then-else construct.
Syntax:
The syntax for the case-else statement is:
case (expression) of L1 : S1; L2 : S2; ... ... Ln: Sn; else Sm; end;
Flow Diagram:
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