; is used to separate statements, in contrast to other programming language where its purpose is to terminate a statement.
In a block a semicolon without a preceding (qualified) statement indicates an empty statement.
Since language constructs only in their entirety constitute statements, semicolons may not split their components.
; can not 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 only if it's been zero before.
As a consequence, and general advice, always put everything in compound statements (i.e. embrace your statements by
end) where it's allowed, in order to mitigate such issues.
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.