Wiki


Pascal - Case Else Statement

Locked

User Rating: 3 / 5

Star ActiveStar ActiveStar ActiveStar InactiveStar Inactive
 
Contents[Hide]

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:

else case statement

 

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