Merge pull request #1872 from luehm/c_cases

[C/en] Added tidbit about fall-though in switch statements.
This commit is contained in:
Geoff Liu 2015-12-18 17:22:50 -05:00
commit 6eeb1f962e

View File

@ -313,6 +313,12 @@ int main (int argc, char** argv)
case 1: case 1:
printf("Huh, 'a' equals 1!\n"); printf("Huh, 'a' equals 1!\n");
break; break;
// Be careful - without a "break", execution continues until the
// next "break" is reached.
case 3:
case 4:
printf("Look at that.. 'a' is either 3, or 4\n");
break;
default: default:
// if `some_integral_expression` didn't match any of the labels // if `some_integral_expression` didn't match any of the labels
fputs("error!\n", stderr); fputs("error!\n", stderr);