JRT Pascal User's Guide version 3.0 NOT FOR SALE -154- 14. Extended CASE statement Format CASE selector_expression OF label_expression ... , label_expression : statement; ... ... ELSE : statement; END The CASE statement is used to select one of several statements for execution based on the value of the selector_expression. The selector_expression and the label_expression must be compatibile data types. The label_expressions are evaluated sequentially. If one is found equal to the selector, the corresponding statement is executed. If none are equal, then the optional ELSE clause statement is executed. The ELSE clause is a JRT Pascal extension. Also, standard Pascal allows only constants as labels, while expressions are allowed by JRT Pascal. Not more than 128 label clauses are allowed in one CASE statement. Not more than 128 labels per label clause are allowed. The statements should be followed by a semicolon. The semicolon is optional on the last statement in the CASE statement. Examples: CASE I OF 2 : WRITELN('I IS 2'); 4 : WRITELN('I IS 4'); ELSE : WRITELN('I IS NOT 2 OR 4'); END; CASE LANGUAGE OF (* STRING EXPRESSION *) 'PASCAL' : YEAR := 1970; 'PL/I' : YEAR := 1964; 'BASIC' : YEAR := 1965; END; Compliments of Merle Schnick SECTION 14: Extended CASE statement JRT Pascal User's Guide version 3.0 NOT FOR SALE -155- (* EXAMPLE OF EXPRESSIONS IN LABELS *) CASE ANGLE OF PHI : WRITELN('PHI'); 2.0 * PHI : WRITELN('TWO PHI'); 3.0 * PHI : WRITELN('THREE PHI'); ELSE : WRITELN('ANGLE NOT ON NODE'); END; (* EXAMPLE OF BOOLEAN SELECTOR AND LABEL EXPRESSIONS *) (* CHECK VOLTAGE V FOR VALID RANGE *) CASE TRUE OF (V > 2.5) AND (V < 4.3) : PROCESS_RANGE_1; (V > 5.6) AND (V <= 14.08) : PROCESS_RANGE_2; (V > 35.6) AND (V <= 100.0) : PROCESS_RANGE_3; ELSE : WRITELN('VOLTAGE OUT OF VALID RANGES:',V); END; Compliments of Merle Schnick SECTION 14: Extended CASE statement S_RANGE_3; ELSE : WRITELN('VOLTAGE OUT OF VALID RANGES:',V); END;