Difference between revisions of ";"
(Remove everything that states a semicolon can be immediately before an else statement that belongs to an if statement. Add example of semicolon before else in a case statement) |
m ((a clear all break instead of several (in fact any arbitrary number) of breaks). Thanks to Kai for showing me how to.) |
||
Line 9: | Line 9: | ||
(In order to explain usage, where Pascal keywords are referred to in the text of this article, they are shown in UPPER case. Program listings will use lower case.) | (In order to explain usage, where Pascal keywords are referred to in the text of this article, they are shown in UPPER case. Program listings will use lower case.) | ||
− | <br | + | <br clear="all"/> |
The semicolon is generally mandatory, and is required after every statement. The places where it is optional are | The semicolon is generally mandatory, and is required after every statement. The places where it is optional are |
Revision as of 14:48, 4 April 2018
│
English (en) │
suomi (fi) │
français (fr) │
The semicolon ASCII or the unicode value is 59 (Hexadecimal $3B).
The semicolon, ; is used to separate statements (unlike other programming languages where it is used to terminate a statement). It is mandatory for most statements, voluntary in some statements, and forbidden in one particular statement.
(In order to explain usage, where Pascal keywords are referred to in the text of this article, they are shown in UPPER case. Program listings will use lower case.)
The semicolon is generally mandatory, and is required after every statement. The places where it is optional are
- before an END statement
A semicolon is forbidden
- immediately before an ELSE statement that belongs to an if statement
Notice that a semicolon can occur immediately before an else statement that belongs to a case statement.
Consider the following:
case a of
true: if b then DoB;
else DoNotA;
end;
The else part belongs to the case statement.
DoNotA will be executed if none of the case labels (just one in this case) applies.
Now if you leave out the semicolon after DoB
case a of
true: if b then DoB
else DoNotB;
end;
The else statement now is part of the "if b".
DoNotB will only be executed if a is true, and b is false.
single characters |
|
character pairs |
|