From Free Pascal wiki
Revision as of 00:57, 20 October 2018 by Kai Burghardt (talk | contribs) (→‎necessity: wording)
Jump to navigationJump to search

English (en) suomi (fi) français (fr)


The semicolon ; 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. Most notably ; can not appear immediately before an else that is part of an if  then branch. However, ; 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;

If c is zero, it remains zero, but becomes -1 otherwise.

	case c of
		0: if false then c := 42
		else c := -1;

Here, 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 begin and end) where it's allowed, in order to mitigate such issues.

other remarks

In the ASCII character set the semicolon takes the value 59 (hexadecimal $3B).

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.

Also historically, 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.

navigation bar: topic: Pascal symbols
single characters

+ (plus)  •  - (minus)  •  * (asterisk)  •  / (slash)
= (equal)  •  > (greater than)  •  < (less than)
. (period)  •  : (colon)  •  ; (semi colon)
^ (hat)  •  @ (at)
$ (dollar sign)  •  & (ampersand)  •  # (hash)
' (single quote)

character pairs

<> (not equal)  •  <= (less than or equal)  •  := (becomes)  •  >= (greater than or equal)

 •  >< (symmetric difference)  •  // (double slash)