HMcG
HMcG

Reputation: 2060

Delphi case statement for integer ranges

I have a function which is being passed an integer value, representing a step value. There are 5 seperate conditions I want to test for: Value =0 Value =1 Value =-1 Value >1 Value <-1

Currently this is implemented as a set of if statements, and I would like to change this for a case statement. I have no problems with the specific value cases, or even a limited range (say 1..10) but how do i write a case representing Value >1 , or Value <-1?

Upvotes: 10

Views: 12505

Answers (1)

Andreas Rejbrand
Andreas Rejbrand

Reputation: 108963

var
  MyValue: integer;

...

case MyValue of
  Low(Integer)..-2:
    beep;
  -1:
    beep;
  0:
    beep;
  +1:
    beep;
  2..High(Integer):
    beep;
end;

Upvotes: 27

Related Questions