[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 9.38 case

### Synopsis

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

or, with alternative statement sequence:

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

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

    foo = record
      field declarations
    case bar: variant type of
      selector: (field declarations);
      selector: (field declarations);
      ...
    end;

or, without a variant selector field,

    foo = record
      field declarations
    case variant type of
      selector: (field declarations);
      selector: (field declarations);
      ...
    end;

### Description

``case'` opens a case statement. For further description see section 8.1.7.4 case Statement.

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

### Conforming to

The ``case'` statement is defined in ISO-7185 Pascal and supported by all known Pascal variants.

According to ISO 7185 Pascal, the selector type must be a named type. GNU Pascal, UCSD and Borland Pascal also allow a subrange here.

The alternative statement execution with ``otherwise'` it is an Extended Pascal extension; with ``else'` it is a Borland Pascal extension. In GNU Pascal, both are allowed.

### Example

    program CaseDemo;
    var
      Foo: String (10);
      Bar: Integer;
    begin
      WriteLn ('Enter up to ten arbitrary characters:');
      ReadLn (Foo);
      for Bar := 1 to Length (Foo) do
        begin
          Write (Foo[Bar], ' is ');
          case Foo[Bar] of
            'A' .. 'Z', 'a' .. 'z':
              WriteLn ('an English letter');
            '0' .. '9':
              WriteLn ('a number');
          otherwise
            WriteLn ('an unrecognized character')
          end
        end
    end.

### See also

section 8.1.7.3 if Statement, section 8.2.10.4 Record Types

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html