Node: case Statement, Next: for Statement, Previous: if Statement, Up: Statements

##### case Statement

         case expression of
           selector: statement;
           ...
           selector: statement;
         end

or, with alternative statement sequence:

         case ordinal_expression of
           selector: statement;
           ...
           selector: statement;
         otherwise                   { ``else'' instead of ``otherwise'' allowed }
           statement;
           ...
           statement;
         end

or, as part of the invariant `record` type definition:

         type
           foo = record
             field_declarations
           case bar: variant_type of
             selector: (field_declarations);
             selector: (field_declarations);
             ...
           end;

or, without a variant selector field,

         type
           foo = record
             field_declarations
           case variant_type of
             selector: (field_declarations);
             selector: (field_declarations);
             ...
           end;

The `case` statement compares the value of ordinal_expression to each selector, which can be a constant, a subrange, or a list of them separated by commas, being compatible with the result of ordinal_expression. Note: duplicate selectors or range crossing is not allowed unless {$borland-pascal} is specified. In case of equality the corresponding statement is executed. If `otherwise` is specified and no appropriate selector matched the expression, the series of statements following `otherwise` is executed. As a synonym for `otherwise`, `else` can be used. The semicolon before `otherwise` is optional.

@@ ???? The expression must match one of the selectors in order to continue, unless an alternative statement series is specified.

For `case` in a variant record type definition, see Record Types.

#### See also

if Statement