Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation/zh CN

한국어 · Deutsch · English · Français · Български · Русский · 中文(中国) · 日本語

1G - 标点符号和缩进 (原作者: Tao Yue, 状态: 未更改)

由于Pascal会忽略行尾空格,标点符号的作用是告诉编译器语句的结束。

你“必须”在下列地方使用分号:

BEGIN-END块中最后一条语句末尾分号不是必需的。 虽然最后一条语句末尾的分号没有用,我却总是加上它,并且建议你也这样做。因为有时你可能需要在末尾添加语句,如果最后没有加分号,你就必须记着加上它,与其如此不如一开始就加上它。

缩进不是必需的。但它有助于使程序结构更清晰明了。不使用缩进的程序看起来是这个样子:

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

使用缩进后,看起来好很多:

pascal
program NotAsStupid;

const
  a = 5;
  b = 385.3;

var
  alpha,
  beta : real;

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

一般情况下,缩进每个语句块。块(如 const 和 var 块) 之间换行。流行的编辑器(IDE或集成开发环境) 都支持代码缩进。 你可以根据自己的喜好自定义缩进(使用3个或4个空格做为1个制表符)。

正确的缩进使得代码更容易阅读,适当的注释对你和他人也有很大帮助。

上一页 目录 下一页

From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation/zh CN", 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 .

Talk about this page

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