Previous: 2.2.9.2. Compound Statement To the Table of Contents Next: 2.2.9.4. For Statement
2.2.9.2. Compound Statement Table of Contents 2.2.9.4. For Statement

- 2.2.9.3. -
Table of Contents
2. TMT Pascal Language Description
2.2. Pascal Language Structure
2.2.9. Statements
2.2.9.3. Case Statement


2.2.9.3. 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: 2.2.9.2. Compound Statement To the Table of Contents Next: 2.2.9.4. For Statement
2.2.9.2. Compound Statement Table of Contents 2.2.9.4. For Statement

- 2.2.9.3. -