The Case Statement resembles the if statement. Think of it as a combination of several if statements. The syntax is as follows:

Case Statement

Syntax

where the case labels have following format:

Case Label

Syntax

The general form is:

case any-variable of
label-1 : statement-1;
label-2 : statement-2;
:
label-n : statement-3
end

label-x can contain many or just 1 value of the same type as the any-variable.

Important notes:

Lets see how the case statement works on an example:

program isitevenorodd(input,output);
var
i:integer;
begin
read(i);
case i of
2,4,6,8 : writeln('i is even);
1,3,5,7,9" writeln('i is odd')
end
 
A First Look A First Look at Pascal Basic Input/Output Identifiers & Types
Constants Standard Functions If..Then Statement Case Statement
Repetitions Procedures and Functions Enumerated /Subrange Types Sets
I/O, Text Files Arrays Records Recursion
Pointer How to Debug Previous Exam Questions Advanced
ASCII Code Table Homepage University Homepage Computer Engineering Dept.