Difference between revisions of ";"
m (replace legacy syntaxhighlight syntax) |
(list all occurrences of semicolons, restructure accordingly, typos) |
||
Line 2: | Line 2: | ||
<div style="float:left; margin: 0 25px 20px 0; padding:50px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777; clear:both;">;</div> | <div style="float:left; margin: 0 25px 20px 0; padding:50px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777; clear:both;">;</div> | ||
− | The '''semicolon''' <syntaxhighlight lang="pascal" inline>;</syntaxhighlight> is used to ''separate'' statements, in contrast to other programming language where its purpose is to ''terminate'' a statement | + | The '''semicolon''' <syntaxhighlight lang="pascal" inline>;</syntaxhighlight> is used to |
− | + | * conclude a declaration, | |
+ | * conclude a constant, <syntaxhighlight lang="delphi" inline>resourceString</syntaxhighlight>, or [[Type|<syntaxhighlight lang="pascal" inline>type</syntaxhighlight>]] definition, | ||
+ | * 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. | ||
+ | == statement separator == | ||
== necessity == | == necessity == | ||
Since language constructs only in their entirety constitute statements, semicolons may not split their components. | Since language constructs only in their entirety constitute statements, semicolons may not split their components. | ||
− | Most notably <syntaxhighlight lang="pascal" inline>;</syntaxhighlight> | + | Most notably <syntaxhighlight lang="pascal" inline>;</syntaxhighlight> cannot appear immediately before an [[Else|<syntaxhighlight lang="pascal" inline>else</syntaxhighlight>]] that is part of an [[If and Then|<syntaxhighlight lang="pascal" inline>if … then</syntaxhighlight> branch]]. |
However, <syntaxhighlight lang="pascal" inline>;</syntaxhighlight> in front of an [[End|<syntaxhighlight lang="pascal" inline>end</syntaxhighlight>]] usually is not necessary, but optional and it does not harm insert one anyway. | However, <syntaxhighlight lang="pascal" inline>;</syntaxhighlight> in front of an [[End|<syntaxhighlight lang="pascal" inline>end</syntaxhighlight>]] usually is not necessary, but optional and it does not harm insert one anyway. | ||
Line 24: | Line 31: | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Here, <syntaxhighlight lang="pascal" inline>c</syntaxhighlight> only becomes <syntaxhighlight lang="pascal" inline>-1</syntaxhighlight> | + | Here, <syntaxhighlight lang="pascal" inline>c</syntaxhighlight> only becomes <syntaxhighlight lang="pascal" inline>-1</syntaxhighlight> if it has been zero before. |
− | As a consequence, and general advice, always put everything in compound statements (i. | + | As a consequence, and general advice, always put everything in compound statements (i. e. embrace your statements by [[Begin|<syntaxhighlight lang="pascal" inline>begin</syntaxhighlight>]] and <syntaxhighlight lang="pascal" inline>end</syntaxhighlight>) where it is allowed, in order to mitigate such issues. |
− | == | + | === empty statement === |
− | In | + | In a sequence a semicolon without a preceding (qualified) statement indicates an '''empty statement'''. |
Historically empty statements were used in conjunction with [[Label|labels]]. | Historically empty statements were used in conjunction with [[Label|labels]]. | ||
Line 36: | Line 43: | ||
Also historically, [[Case|<syntaxhighlight lang="pascal" inline>case</syntaxhighlight>-statements]] had to list all possible values the selector variable theoretically could have. | Also historically, [[Case|<syntaxhighlight lang="pascal" inline>case</syntaxhighlight>-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 <syntaxhighlight lang="pascal" inline>case</syntaxhighlight>-statement in order to fulfill this requirement, an empty statement is the shortest possible way to implement the situation. | Now, if a value or range did not imply any action, yet had to be listed inside the <syntaxhighlight lang="pascal" inline>case</syntaxhighlight>-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 <syntaxhighlight lang="pascal" inline>59</syntaxhighlight> ([[Hexadecimal|hexadecimal]] <syntaxhighlight lang="delphi" inline>$3B</syntaxhighlight>). | ||
{{Symbols}} | {{Symbols}} |
Revision as of 14:48, 4 September 2020
│
English (en) │
suomi (fi) │
français (fr) │
The semicolon ;
is used to
- conclude a declaration,
- conclude a constant,
resourceString
, ortype
definition, - 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.
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:
case c of
0: if false then c := 42;
else c := -1;
end;
If c
is zero, it remains zero, but becomes -1
otherwise.
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.
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
).
single characters |
|
character pairs |
|