Pascal - Case Else 语句


case -else语句在case标签后使用else术语,就像if-then-else结构一样。

句法

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.htm