Difference between revisions of "Basic Pascal Tutorial/Chapter 3/CASE/ja"

From Lazarus wiki
Jump to navigationJump to search
Line 1: Line 1:
{{CASE}}
+
{{CASE/ja}}
  
 
3Cb - CASE (著者: Tao Yue, 状態: 原文のまま変更なし)
 
3Cb - CASE (著者: Tao Yue, 状態: 原文のまま変更なし)
  
Case は case 文を実行する。 case 文は各選択肢の順序表現を比較する。各選択肢は [[Const/ja|constant]]であったり、部分範囲、あるいは [[Comma/ja|commas]]で区切られたリストである。Selector field separated to action field by [[Colon]].
+
Case は case 文を実行する。 case 文は各選択肢の順序表現を比較する。各選択肢は [[Const/ja|constant]]であったり、部分範囲、あるいは [[Comma/ja|commas]]で区切られたリストである。選択肢フィールドは[[Colon]]によってアクション・フィールドと分けられる。
  
Suppose you wanted to branch one way if <tt>b</tt> is <tt>1, 7, 2037,</tt> or <tt>5</tt>; and another way if otherwise. You could do it by:
+
<tt>b</tt> <tt>1、 7、 2037、</tt> あるいは <tt>5</tt>のいずれかで1方向に分岐させ、それ以外の場合には他の処理をさせたとしよう。それには次のようになる。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
if (b = 1) or (b = 7) or (b = 2037) or (b = 5) then
 
if (b = 1) or (b = 7) or (b = 2037) or (b = 5) then
   Statement1
+
   文1
 
else
 
else
   Statement2;
+
   文2;
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 13:46, 10 August 2015

Template:CASE/ja

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

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

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

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

But in this case, it would be simpler to list the numbers for which you want Statement1 to execute. You would do this with a case statement:

case b of
  1,7,2037,5: Statement1;
  otherwise   Statement2
end;

The general form of the case statement is:

case selector of
  List1:    Statement1;
  List2:    Statement2;
  ...
  Listn:    Statementn;
  otherwise Statement
end;

The otherwise part is optional. When available, it differs from compiler to compiler. In many compilers, you use the word else instead of otherwise.

selector is any variable of an ordinal data type. You may not use reals!

Note that the lists must consist of literal values. That is, you must use constants or hard-coded values -- you cannot use variables.

previous contents next