Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

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

	}
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
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?
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,510
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
 

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
hello bigdogguru,can you plz provide some useful codes in c using switch case:I am doing like

switch(period){
case 15:printf(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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top