Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation/ja: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation/ja
| Old | New | Line | |
|---|---|---|---|
| 1 | + | 1G - 区切りとインデント (著者: Tao Yue, 状態: 原文のまま) | |
| 2 | + | ||
| 3 | + | Pascal は行末とスペースを無視するので文が終わったことをコンパイラに伝えるため区切り(punctuation)が必要になる。 | |
| 4 | + | ||
| 5 | + | 以下の場合にはセミコロンをつけなくてはならない。 | |
| 6 | + | ||
| 7 | + | - プログラムのヘッド | |
| 8 | + | - 定数の定義 | |
| 9 | + | - 変数宣言 | |
| 10 | + | - タイプの定義(後から説明する) | |
| 11 | + | - ほとんど全ての命令文 | |
| 12 | + | ||
| 13 | + | `BEGIN-END`ブロックの最後の命令文、ENDのすぐ前の命令文になるが、それにはセミコロンは必要ない。しかし、セミコロンを加えても害はないし、もし突然その命令文を上の方に移動させなくてはならなくなったなどという場合には、セミコロンを付け加える手間を省いてくれる。 | |
| 14 | + | ||
| 15 | + | インデントは必ずしも必要はない。しかし、プログラマーには非常に有益である。なぜなら、プログラムを明確にする手助けになるからである。もし、望むなら以下のようにプログラムを示すこともできるだろう。 | |
| 16 | + | ||
| 17 | + | ``` pascal | |
| 18 | + | program Stupid; const a=5; b=385.3; var alpha,beta:real; begin | |
| 19 | + | alpha := a + b; beta:= b / a end. | |
| 20 | + | ``` | |
| 21 | + | ||
| 22 | + | しかし、以下のように示した方がずっとよい。 | |
| 23 | + | ||
| 24 | + | ``` pascal | |
| 25 | + | program NotAsStupid; | |
| 26 | + | ||
| 27 | + | const | |
| 28 | + | a = 5; | |
| 29 | + | b = 385.3; | |
| 30 | + | ||
| 31 | + | var | |
| 32 | + | alpha, | |
| 33 | + | beta : real; | |
| 34 | + | ||
| 35 | + | begin (* main *) | |
| 36 | + | alpha := a + b; | |
| 37 | + | beta := b / a; | |
| 38 | + | end. (* main *) | |
| 39 | + | ``` | |
| 40 | + | ||
| 41 | + | 一般的に、ブロックごとにインデントをした方がよい。ブロック間の線(定数(const)ブロックと変数(var)ブロックの間にあるような線)はスキップすればよい。現在のプログラミング環境(IED、あるいは統合開発環境)は Pascal の文法を理解し、タイプすればインデントしてくれることが多い。自分の好み(タブを3スペースあるいは4スペースにするなど)でインデントをカスタマイズすることができる。 | |
| 42 | + | ||
| 43 | + | 適切なインデントはどうコードを働かせるかを決めるのを、よりたやすくしてくれる。だが、思慮深いコメントを加えれば、それはさらに大きな助けになるのである。 | |
| 44 | + | ||
| 45 | + | | | | | | |
| 46 | + | |----|----|----| | |
| 47 | + | | [[Basic Pascal Tutorial/Chapter 1/Standard Functions/ja|previous]] | [[Basic Pascal Tutorial/Contents/ja|contents]] | [[Basic Pascal Tutorial/Chapter 1/Programming Assignment/ja|next]] | | |
| 48 | + | ||
| 49 | + | --- | |
| 50 | + | *From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation/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](/wiki-contact).* |
