Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation/zh CN: 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/zh CN

OldNewLine
1+1G - 标点符号和缩进 (原作者: Tao Yue, 状态: 未更改)
2+
3+由于Pascal会忽略行尾空格,标点符号的作用是告诉编译器语句的结束。
4+
5+你“必须”在下列地方使用分号:
6+
7+- 程序标题
8+- 每个常量定义
9+- 每个变量的声明
10+- 每个类型定义 (稍后讨论)
11+- 几乎所有语句
12+
13+`BEGIN-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 块) 之间换行。流行的编辑器(IDE或集成开发环境) 都支持代码缩进。 你可以根据自己的喜好自定义缩进(使用3个或4个空格做为1个制表符)。
42+
43+正确的缩进使得代码更容易阅读,适当的注释对你和他人也有很大帮助。
44+
45+| | | |
46+|----|----|----|
47+| [[Basic Pascal Tutorial/Chapter 1/Standard Functions/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 1/Programming Assignment/zh CN|下一页]] |
48+
49+---
50+*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](/wiki-contact).*

Back to history