Continue to Site

# Case statement condition problem

Status
Not open for further replies.

#### sureshaa

##### Member level 1
Hi ,

I want to check the condition in case like below,
case op is
when cond1 => statement;
when cond2 => statement;
when cond3 => statement;
when cond4 => statement;
when others => Null;
end case;

My conditions are within some range. Example 1 to 20, 21 to 40, 41 to 60, 61 to 81.I could not write all the numbers between 1 to 20.Is there any command for checking range in case condition.

Suresh

i hope you are using C. first you use "if" statement to assign some fixed value to some variable(say x=1) if your condition is within first range i.e. 1-20. give x2 for condition 21-40 and so on. now u you can easily use switch case statement for x.
this is one of the solution. there can be much easier solution also.

Hi ,

I want to check the condition in case like below,
case op is
when cond1 => statement;
when cond2 => statement;
when cond3 => statement;
when cond4 => statement;
when others => Null;
end case;

My conditions are within some range. Example 1 to 20, 21 to 40, 41 to 60, 61 to 81.I could not write all the numbers between 1 to 20.Is there any command for checking range in case condition.

The only other option on the conditions is

case op is
when 1 | 2 | 3 => statement;
when 21 | 22 | 23 => statement;
...

But listing 20 items on one line will look a bit messy. The other option would be to compute a variable that already classifies them for you. In your case, if you took 'op' and divided it by 20 and then used the case statement on that new variable like this...

Code:
op_div20 := op / 20;
case op_div20 is
when 0 => statement;
when 1 => statement;
when 2 => statement;
when others => null;
end case;

Kevin Jennings

Hi ppdr,

Thanks for your reply. I agree. but I need to know whether any syntax (to use within case itself) is there without using any combinational logic condition checking or if checking. To add more clarity,

case count is
when (1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20) => statement;
.
.
.
.
End case;
To replace 1|2|3|......19|20 sequence, is there any statements are there (combinational logic condition checking or if checking) ?

If you are asking for this type of syntax
Code:
Case xx is
when 1 to 20 =>
when 21 to 40 =>
.
.
.
when 61 to 80 =>
end case

Regards

Points: 2

### ppdr123

Points: 2
Ya its fine now.

but i think Sureshaa want to execute some statement if the number is between range 1-20,21-40 .......

Status
Not open for further replies.