Sign in Join
Wiki copytemporary

;: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: ;

OldNewLine
1+;
2+
3+The **semicolon** `;` is used to
4+
5+- conclude a [[Declaration|declaration]],
6+- conclude a constant, `resourceString`, or [[Type|type]] definition,
7+- separate formal parameters in a routine signature,
8+- separate a routine declaration from its attributes,
9+- terminate the program header,
10+- separate alternatives in variant records, and to
11+- *separate* statements, in contrast to other programming language where its purpose is to *terminate* a statement.
12+
13+## statement separator
14+
15+### necessity
16+
17+Since language constructs only in their entirety constitute statements, semicolons may not split their components. Most notably `;` cannot appear immediately before an [[Else|else]] that is part of an [[If and Then|if … then branch]]. However, `;` in front of an [[End|end]] usually is not necessary, but optional and it does not harm insert one anyway.
18+
19+As a demonstration, that a single semicolon can make the difference, consider the following listings:
20+
21+``` pascal
22+ case c of
23+ 0: if false then c := 42;
24+ else c := -1;
25+ end;
26+```
27+
28+If `c` is zero, it remains zero, but becomes `-1` otherwise.
29+
30+``` pascal
31+ case c of
32+ 0: if false then c := 42
33+ else c := -1;
34+ end;
35+```
36+
37+Here, `c` only becomes `-1` if it has been zero before. As a consequence, and general advice, always put everything in compound statements (i. e. embrace your statements by [[Begin|begin]] and `end`) where it is allowed, in order to mitigate such issues.
38+
39+> **Note:** Using `otherwise` (an [[Extended Pascal]] extension) instead of `else` in `case`-statements may prevent such mistakes.
40+
41+### empty statement
42+
43+In a sequence a semicolon without a preceding (qualified) statement indicates an **empty statement**.
44+
45+Historically empty statements were used in conjunction with [[Label|labels]]. Originally labels can only defined where a statement exists. If for instance a whole list of statements had to be bypassed, but no qualified statement followed thereafter, the empty statement still provided the possibility.
46+
47+Also historically, [[Case|case-statements]] had to list all possible values the selector variable theoretically could have. Now, if a value or range did not imply any action, yet had to be listed inside the `case`-statement in order to fulfill this requirement, an empty statement is the shortest possible way to implement the situation.
48+
49+## other remarks
50+
51+In the [[ASCII]] character set the semicolon takes the value `59` ([[Hexadecimal|hexadecimal]] `$3B`).
52+
53+---
54+*From the Free Pascal wiki, page ";", as it stood on 2021-07-04 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