Pascal-nested-case-statement

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

パスカル-入れ子になったケースステートメント

外側の* caseステートメント*のステートメントシーケンスの一部として* caseステートメント*を使用することができます。 内側と外側のケースの*ケース定数*に共通の値が含まれていても、競合は発生しません。

構文

ネストされたcase文の構文は次のとおりです-

case (ch1) of
   'A': begin
      writeln('This A is part of outer case' );
         case(ch2) of
            'A': writeln('This A is part of inner case' );
            'B': ( *case code* )
            ...
         end; {end of inner case}
      end; ( *end of case 'A' of outer statement* )
   'B': ( *case code* )
   'C': ( *case code* )
   ...
end; {end of outer case}

次のプログラムは、概念を示しています。

program checknestedCase;
var
   a, b: integer;
begin
   a := 100;
   b := 200;

   case (a) of
      100: begin
         writeln('This  is part of outer statement' );
         case (b) of
            200: writeln('This  is part of inner statement' );
            end;
         end;
      end;

   writeln('Exact value of a is : ', a );
   writeln('Exact value of b is : ', b );
end.

上記のコードをコンパイルして実行すると、次の結果が生成されます-

This is part of outer switch
This is part of inner switch
Exact value of a is: 100
Exact value of b is: 200