Feb 13, 2006 #1 rewclaus Programmer Joined Mar 7, 2005 Messages 16 Location 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
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
Feb 13, 2006 1 #2 xwb Programmer Joined Jul 11, 2002 Messages 6,828 Location GB No - use an if instead Upvote 0 Downvote
Mar 9, 2006 #3 scienzia Programmer Joined Feb 21, 2002 Messages 160 Location IT 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 Upvote 0 Downvote
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
Mar 9, 2006 #4 Salem Programmer Joined Apr 29, 2003 Messages 2,455 Location GB 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': -- Upvote 0 Downvote
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': --