Contents | Prev | Next | Index


Case Statements

The purpose of a case statement is to specify the selection and execution of a statement according to the value of an expression. It starts by first evaluating the expression; then that statement is executed whose case label list contains the obtained value. The case expression has to be a value of a basic type (except reals), of an enumeration or of a subrange type. Its type has to include all case label values, and the case expression and the case labels must be compatible. Case labels are constants, and no value may occur than once. If the case expression value does not match any label, the default statement following symbol ELSE is executed if one exists. Otherwise, the program is aborted.

case_stmt       ::= switch_expr case_list else_case endcase
                ::= switch_expr case_list endcase
switch_expr     ::= CASE expr OF
case_list       ::= case_list ; case
                ::= case
case            ::= case_label_list : stmt
case_label_list ::= case_label_list , case_labels
                ::= case_labels
case_labels     ::= const_expr .. const_expr
                ::= const_expr
else_case       ::= ELSE stmt
                ::= ; ELSE stmt
endcase         ::= END
                ::= ; END

Example:

CASE ch OF
  'A'..'Z' : ReadIdentifier;
  '0'..'9' : ReadNumber;
  '"'      : ReadString;
ELSE         SpecialCharacter;
END


Contents | Prev | Next | Index

Canterbury Pascal for JVM  (Last documentation update Sep 02, 2004)
Copyright © 1999-2004 J.Neuhoff - mhccorp.com  . All rights reserved.
Please send any comments or corrections to neuhoff@mhccorp.com