Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi case statement for integer ranges

Tags:

delphi

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?

like image 486
HMcG Avatar asked Oct 02 '11 18:10

HMcG


1 Answers

var
  MyValue: integer;

...

case MyValue of
  Low(Integer)..-2:
    beep;
  -1:
    beep;
  0:
    beep;
  +1:
    beep;
  2..High(Integer):
    beep;
end;
like image 122
Andreas Rejbrand Avatar answered Oct 18 '22 09:10

Andreas Rejbrand