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

Status
Not open for further replies.

Micro Lover

Member level 2
Joined
Jul 22, 2009
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
pakistan
Activity points
1,614
is it possible to use the Case with Expression

e.g


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

	break;

	}
 

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;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
 

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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…