Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

the Switch statement 1

Status
Not open for further replies.

rewclaus

Programmer
Mar 7, 2005
16
0
0
US
is there a way to make a range limit in the cases within the switch function. For example is it possible to do something like this:

switch (int)
{
case(x to y): {printf("YAY!"); break;}
}

-rewclaus
 
If the x and y have fixed values (here x is 1 and y is 3), you can do:


switch (int)
{
case 1:
case 2:
case 3:
{printf("YAY!"); break;}

}

I would use the if-case, as xwb suggested
 
If you're using gcc, and you're willing to allow compiler extensions in your code, then you can do things like this
Code:
case 'A' ... 'Z':

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top