The GNU case range extension allows case ranges in switch statements:
switch (value) {
case 1 ... 8:
printf(\"Hello, 1 to 8\\n\");
break;
switch(value)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
printf("Hello, 1 to 8\n");
break;
default:
printf("Hello, default\n");
break;
}
EDIT: To answer the comment.
If you have too many cases, then You might want to consider replacing the switch-case with if-else constructs. It can be much cleaner, concise & readable.
if (value >=1 && value <= 8)
{
printf("Hello, 1 to 8\n");
}
else
{
printf("Hello, default\n");
}