;

From Free Pascal wiki
Revision as of 15:59, 2 April 2018 by Bart (talk | contribs) (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)
Jump to navigationJump to search

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.



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)