Pascal - Case Else 语句

case-else 语句在 case 标签后使用 else 术语,就像 if-then-else< /b> 构造。

语法

case-else 语句的语法是 −

case (expression) of
   L1 : S1;
   L2 : S2;
   ...
   ...
   Ln: Sn;
else
   Sm;
end;

流程图

Pascal 中的 Else Case 语句

示例

下面的例子说明了这个概念

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.

当上面的代码被编译并执行时,会产生以下结果 −

You really did not study right!
Your grade is F

❮ pascal_decision_making.html