[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
case expression of selector: statement; ... selector: statement; end; |
case expression of selector: statement; ... selector: statement; otherwise { ``else'' instead of ``otherwise'' is allowed } statement; ... statement; end; |
record
type definition:
foo = record field declarations case bar: variant type of selector: (field declarations); selector: (field declarations); ... end; |
foo = record field declarations case variant type of selector: (field declarations); selector: (field declarations); ... end; |
`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.
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.
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. |
section 8.1.7.3 if Statement, section 8.2.10.4 Record Types
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |