Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 3/CASE/ja

Sent here from CASE/ja.

English · Español · Français · Български · 中文(中国) · 日本語

3Cb - CASE (著者: Tao Yue, 状態: 原文のまま変更なし)

Case は case 文を実行する。 case 文は各選択肢(selector)の順序表現を比較する。各選択肢は constantであったり、部分範囲、あるいは commasで区切られたリストである。選択肢フィールドはColonによってアクション・フィールドと分けられる。

b が 1、 7、 2037、 あるいは 5のいずれかで1方向に分岐させ、それ以外の場合には他の処理をさせるとしよう。それは次のようになる。

pascal
if (b = 1) or (b = 7) or (b = 2037) or (b = 5) then
  ???1
else
  ???2;

しかし、この場合は実行したい文に対応した数字をリストすることで簡単にできる。これは case 文で実行できる。

pascal
case b of
  1,7,2037,5: ???1;
  otherwise   ???2
end;

一般的な case 文の形式は次のようになる。

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

Revision 1, last changed by WikiArchive .

Edited on wiki.freepascal.org by 4 people, 2015–2022

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
DerakunCreated page
Derakun
Derakun
Derakun
Derakun
Derakun
Derakun
FTurtlecorrected template name
TrevFixed syntax highlighting (minor)
Kai BurghardtKai Burghardt moved page CASE/ja to Basic Pascal Tutorial/Chapter 3/CASE/ja: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: PermaLink/149778#Cluttering of... (minor)
Kai Burghardtbypass redirects [cf. discussion]
Kai Burghardtbypass [previously missed] redirect [cf. discussion]
Kai Burghardtbypass language bar/categorization template redirect [cf. discussion] (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.