Does CASE <var> OF effectively mean CASE <var> EQUALS?

163 views Asked by At

Does

CASE <var/expr> OF
      1: <do statement>;
      2: <do statement>;
   3..5: <do statement>;
END;

Always effectively mean:

(in) CASE <var/expr> EQUALS
      1: <do statement>;
      2: <do statement>;
   3..5: <do statement>;
     ^ value/char in range
END;

Translated to natural language? I'm just wondering why this wording choice was made. Otherwise Pascal syntax seems to read so naturally, grammatically. But maybe I understand the 'case statement' incorrectly?

EDIT: added range case, and parenthesis around (in) as it confused people.

1

There are 1 answers

5
Uwe Raabe On

It could be read like "In case var is of value1 do_this, in case var is of value2 do_that...". So it indeed means equal.

A statement like

case v of
  value1: do_this;
  value2: do_that;
else
  do_something_else;
end;

boils down to

if v = value1 then
  do_this
else if v = value2 then
  do_that
else
  do_something_else;