type_case_statement::= 'typecase' ( local_declaration | identifier )
( 'when' types 'then' block)\stern [ 'else' block
] 'end' .
types ::= type_specifier ( ',' type_specifier )\stern .
Example: typecase o:=mail.next when BILL then o.pay when NOTE,
$AD then o.order else drop end
The local declaration of a type case statement must be an initialized declaration for an identifier id. The typecase statement is a block in which this local declaration is valid. Instead of this local declaration the identifier id of a local variable or a parameter of a procedure may be used. All the types in the when-clauses must conform to the type of id.
The type case statement is processed as follows: First the initial
local declaration is processed. Then the type T of the value v of the
initializing expression is compared with the types
in the
when-clauses in textual order. If a clause is found such that T
conforms to
then the block of the first such clause is
prefixed with a local declaration
and then processed. If no
such clause can be found and an else-clause is present then the
block of the else-clause is prefixed with the initial
declaration and processed.
The initializing expression is always evaluated only once.