Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation/ja

From Free Pascal wiki
Revision as of 20:28, 22 July 2015 by Derakun (talk | contribs) (Created page with "{{Punctuation_and_Indentation}} 1G - 区切りとインデント (著者: Tao Yue, 状態: 原文のまま) Pascal は行末とスペースを無視するので文が終わ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

български (bg) Deutsch (de) English (en) français (fr) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

1G - 区切りとインデント (著者: Tao Yue, 状態: 原文のまま)

Pascal は行末とスペースを無視するので文が終わったことをコンパイラに伝えるため区切り(punctuation)が必要になる。

以下の場合にはセミコロンをつけなくてはならない。

  • プログラムのヘッド
  • 定数の定義
  • 変数宣言
  • タイプの定義(後から説明する)
  • ほとんど全ての命令文

The last statement in a BEGIN-END block, the one immediately preceding the END, does not require a semicolon. However, it's harmless to add one, and it saves you from having to add a semicolon if suddenly you had to move the statement higher up.

Indenting is not required. However, it is of great use for the programmer, since it helps to make the program clearer. If you wanted to, you could have a program look like this:

program Stupid; const a=5; b=385.3; var alpha,beta:real; begin 
alpha := a + b; beta:= b / a end.

But it's much better for it to look like this:

program NotAsStupid;

const
  a = 5;
  b = 385.3;

var
  alpha,
  beta : real;

begin (* main *)
  alpha := a + b;
  beta := b / a
end. (* main *)

In general, indent each block. Skip a line between blocks (such as between the const and var blocks). Modern programming environments (IDE, or Integrated Development Environment) understand Pascal syntax and will often indent for you as you type. You can customize the indentation to your liking (display a tab as three spaces or four?).

Proper indentation makes it much easier to determine how code works, but is vastly aided by judicious commenting.

previous contents next