Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Case statement condition problem

Status
Not open for further replies.

sureshaa

Member level 1
Joined
Dec 18, 2012
Messages
41
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,529
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.

Thanks in advance.
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
 
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top