Feb 13, 2006 #1 rewclaus Programmer Mar 7, 2005 16 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
Mar 9, 2006 #3 scienzia Programmer Feb 21, 2002 160 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 Apr 29, 2003 2,455 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': --