; is used to
- conclude a declaration,
- conclude a constant,
- separate formal parameters in a routine signature,
- separate a routine declaration from its attributes,
- terminate the program header,
- separate alternatives in variant records, and to
- separate statements, in contrast to other programming language where its purpose is to terminate a statement.
Since language constructs only in their entirety constitute statements, semicolons may not split their components.
; cannot appear immediately before an
else that is part of an
if … then branch.
; in front of an
end usually is not necessary, but optional and it does not harm insert one anyway.
As a demonstration, that a single semicolon can make the difference, consider the following listings:
case c of 0: if false then c := 42; else c := -1; end;
c is zero, it remains zero, but becomes
case c of 0: if false then c := 42 else c := -1; end;
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
end) where it is allowed, in order to mitigate such issues.
In a sequence a semicolon without a preceding (qualified) statement indicates an empty statement.
Historically empty statements were used in conjunction with 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.
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.