Sign in Join
Wiki copytemporary

;

English · Français · Suomi

;

The semicolon ; is used to

statement separator

necessity

Since language constructs only in their entirety constitute statements, semicolons may not split their components. Most notably ; cannot 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:

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

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

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

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

Note: Using otherwise (an Extended Pascal extension) instead of else in case-statements may prevent such mistakes.

empty statement

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.

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.

other remarks

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


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.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.