开发者

Delphi case statement for integer ranges

开发者 https://www.devze.com 2023-04-09 19:36 出处:网络
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:

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 Va开发者_运维知识库lue >1 , or Value <-1?


var
  MyValue: integer;

...

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

精彩评论

暂无评论...
验证码 换一张
取 消