Basic Pascal Tutorial/Chapter 3/IF/ja
Sent here from IF/ja.
English · Français · Български · 中文(中国) · 日本語
3Ca - IF (著者: Tao Yue, 状態: 原文のまま修正なし)
IF 文はブール式の結果をもとに分岐を可能にする。 1方向の分岐の形式は次のようになる。
if ???????????? then
??????????????????;もし、ブール式が true と評価されたなら、文が実行される。そうでない場合には、スキップされる。
IF 文は1つの文のみ受け取る。文の組み合わせで分岐させたいなら、 begin-end ブロック で文を囲む。
if ???????????? then
begin
???1;
???2
end;2方向の分岐もある。
if ???????????? then
??????????????????
else
??????????????????;ブール式が FALSE と評価されると、 else に続く文が実行される。 else の前の文にはセミコロンをつけてはいけないことに注意しよう。つけてしまうと、コンピュータはそれを1方向の選択と扱い、 else がどこからきたのかわからないままになってしまうからである。
複数選択が必要な場合には、単に if 文を入れ子にすればよい。
if ??????1 then
???1
else
if ??????2 then
???2
else
???3;入れ子にする場合には注意が必要である。しばしばコンピュータはあなたが望んでいることとは違うことを実行するからである。
if ??????1 then
if ??????2 then
???2
else
???1;else は常に直前の if とマッチする。従って、コンピュータはコードの前のブロックを次のように解釈する。
if ??????1 then
if ??????2 then
???2
else
???1;空の文(null statement)を使って次のようにするすることもできる。
if ??????1 then
if ??????2 then
???2
else
else
???1;あるいは begin-end のブロックを利用することもできる。しかし、コードをきれいにする最良の方法は条件を書き換えることだろう。
if not ??????1 then
???1
else
if ??????2 then
???2;この例は not 演算子を非常にうまく利用している。もし、条件1が次のようなブール式だとすると、 (not(a < b) or (c + 3 > 6)) and g、式を反転させるのは NOT をつけるだけでは済まず、より難しいものとなるだろう。
プログラムのロジックを人間に伝えるにはインデントがどれほど重要かにも気がついただろう。しかし、コンパイラはインデントは無視してしまうのである。
| previous | contents | next |
From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 3/IF/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.
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.
| When | Who | What changed |
|---|---|---|
| Derakun | Created page | |
| Derakun | ||
| Derakun | ||
| Derakun | ||
| Derakun | ||
| Derakun | ||
| Derakun | ||
| Derakun | ||
| FTurtle | corrected template name | |
| Trev | Fixed syntax highlighting (minor) | |
| Kai Burghardt | Kai Burghardt moved page IF/ja to Basic Pascal Tutorial/Chapter 3/IF/ja: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: PermaLink/149778#Cluttering of main... (minor) | |
| Kai Burghardt | bypass redirects [cf. discussion] | |
| Kai Burghardt | bypass [previously missed] redirect [cf. discussion] | |
| Kai Burghardt | bypass 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.
