I'm using the following GCC extension to simplifying a big switch statement:
case 'a' ... 'z':
...
What's the proper/portable way to do this -- i.e., go through all the letters in a big switch -- or for this should a switch not be used.
Remember that default
can be used for performing a task when none of the cases is true:
switch (x)
{
case 1:
case 2:
printf("%d
", x);
break;
default:
if (islower(x))
{
puts("alpha");
}
break;
}
Another way using the infamous goto
:
if (islower(x))
goto alpha;
switch (x)
{
alpha:
printf("alpha
");
break;
case 1:
case 2:
printf("%d
", x);
break;
}