next up previous contents
Next: Loops and the Break Up: Statements Previous: Case Statements

Type Case Statements

 
  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 tex2html_wrap_inline1707

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 tex2html_wrap_inline1933 in the when-clauses in textual order. If a clause is found such that T conforms to tex2html_wrap_inline1933 then the block of the first such clause is prefixed with a local declaration tex2html_wrap_inline2413 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.


Martin Trapp
Mon Feb 17 16:49:16 MET 1997