Skip to content

Instantly share code, notes, and snippets.

@twopoint718
Created September 15, 2021 22:26
Show Gist options
  • Save twopoint718/00b3810f39ea2f15f6ab129197abf2ce to your computer and use it in GitHub Desktop.
Save twopoint718/00b3810f39ea2f15f6ab129197abf2ce to your computer and use it in GitHub Desktop.
Cases in a switch statement can have ranges (there must be space around the `...` though). It is supported by GCC and Clang.
#include <stdio.h>
int
main(int argc, char **argv) {
int i = 0;
switch(i) {
case 0 ... 10:
printf("0 through 10\n");
break;
default:
printf("not 0 through 10\n");
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment