Previous: Compound Statement To the Table of Content Next: For Statement

- 2.2.9.3 -
TMT Pascal Language Description
Pascal Language Structure
Statements

Case Statement

The case statement selects from a list of statements basing it's decision on the value of an expression. case statements take the following form:
case expression of
  Selector : statement
  [else statement]
end;
where expression is a value of ordinal type. The case expression value is matched against each Selector. If a match exists the statement following the matching Selector is executed. Control is then transferred out of the case. If no Selector matches the case expression then control is passed to an optional else clause. Selector must evaluate to a constant at compile time and is defined as:
  expression [..expression] [,expression [..expression]]}
If .. is specified followed by another expression the case applies to the entire range between the first expression and the second expression. The following is an example of the case statement:
case Int of
  5       : WriteLn('Int is 5');
  7..12,15: WriteLn('Between 7..12 or 15');
  else
    begin
      WriteLn('Undefined.');
      GetNextInt;
    end;
  end;
Performance for large case statements improves if the most common subcases are listed first.


Previous: Compound Statement To the Table of Content Next: For Statement
Compound Statement Table of Content For Statement

- 2.2.9.3 -