Basic Pascal Tutorial/Chapter 3/CASE/ja
English · Español · Français · Български · 中文(中国) · 日本語
3Cb - CASE (著者: Tao Yue, 状態: 原文のまま変更なし)
Case は case 文を実行する。 case 文は各選択肢(selector)の順序表現を比較する。各選択肢は constantであったり、部分範囲、あるいは commasで区切られたリストである。選択肢フィールドはColonによってアクション・フィールドと分けられる。
b が 1、 7、 2037、 あるいは 5のいずれかで1方向に分岐させ、それ以外の場合には他の処理をさせるとしよう。それは次のようになる。
if (b = 1) or (b = 7) or (b = 2037) or (b = 5) then
???1
else
???2;しかし、この場合は実行したい文に対応した数字をリストすることで簡単にできる。これは case 文で実行できる。
case b of
1,7,2037,5: ???1;
otherwise ???2
end;一般的な case 文の形式は次のようになる。
case ????????? of
?????????1: ???1;
?????????2: ???2;
...
?????????n: ???n;
otherwise ???
end;otherwise の部分はオプションである。利用できるとしてもコンパイラ次第で異なる。多くのコンパイラでは otherwise の代わりに else を使う。
選択肢はなんらかの順序データ型である。実数は利用できない。
リストは文字値からなっていなくてはならないことに気をつけよう。つまり、定数か変更できない値を使わなくてはならない。言い換えれば変数は使えないのである。
| previous | contents | next |
From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 3/CASE/ja", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
