Pascal-case-else-statement

提供:Dev Guides
移動先:案内検索

パスカル-ケースElseステートメント

*case-else* ステートメントは、 *if-then-else* コンストラクトのように、 *case* ラベルの後に *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