modula-2 home

  Home  
  Tutorial  
  Win32 API  
  Reference  
  Projects  
 

 

Case Statements

Case statements specify the selection and execution of a statement sequence according to the value of an expression. First the case expression is evaluated, then the statement sequence is executed whose case labelllst contains the obtained value. The type of the case expression must be a basic type (except REAL), an enumeration type, or a subrange type, and all labels must be compatible with that type. Case labels are constants, and no value must occur more than once. If the value of the expression does not occur as a label of any case, the statement sequence following the symbol ELSE is selected.

   CaseStatement = CASE expression OF case {"|" case}
     [ELSE StatementSequence] END.
   case = [CaseLabelList ":" StatementSequence].

Example:

   CASE i OF
      O : p := p OR q; x := x+y |
      1 : p := p OR q; x := x-y |
      2 : p := p AND q; x := x*y
   ELSE
   END


Source:

  • Wirth N: Programming in Modula-2, 3rd ed. Springer Verlag, Berlin, 1985.