# [SOLVED]Can i use the Case with Expression , (in switch statement)?

Status
Not open for further replies.

#### Micro Lover

##### Member level 2
is it possible to use the Case with Expression

e.g

Code:
switch (A)
{
case (A > 1 && A < 10):

break;

}

#### Tahmid

I'm not sure, but I think you can depending on the compiler. In VB, I can do this, so I think you can do this in VC++ as well. I don't know about other compilers though.

---------- Post added at 05:24 ---------- Previous post was at 05:22 ----------

However in VB, I would use
Code:
case (> 1 and <10)
You don't need to mention A in the case function as A is the variable which you are testing. Why don't you try it out and see?

#### Micro Lover

##### Member level 2
i tried, but not working

#### bigdogguru

Micro Lover;942988 said:
is it possible to use the Case with Expression

Code:
  switch (A)
{
case (A > 1 && A < 10):

break;

}

The above switch statement is invalid in C and C++. The case label must consist of the reserve word, "case" followed by a constant expression and ending with a colon.

"(A > 1 && A < 10)" is not a constant expression.

BigDog

@ bigdogguru

thnx

#### john120

##### Banned
hello bigdogguru,can you plz provide some useful codes in c using switch case:I am doing like

switch(period){
case 15rintf(lcd_putc,"10%%");
delay_ms(500);

I want to test the period of square wave signal and then if the period is 15ms(viwable on the lcd),I want the lcd to print 10%.;etc

Status
Not open for further replies.

Replies
1
Views
2K
Replies
0
Views
2K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
0
Views
1K