Sign in Join
Wiki copytemporary

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

OldNewLine
1+1G - Punctuation and Indentation (author: Tao Yue, state: unchanged)
2+
3+Since Pascal ignores end-of-lines and spaces, punctuation is needed to tell the compiler when a statement ends.
4+
5+You *must* have a semicolon following:
6+
7+- the program heading
8+- each constant definition
9+- each variable declaration
10+- each type definition (to be discussed later)
11+- almost all statements
12+
13+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.
14+
15+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:
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+But it's much better for it to look like this:
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+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?).
42+
43+Proper indentation makes it much easier to determine how code works, but is vastly aided by judicious commenting.
44+
45+---
46+*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation", 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