switch and break
switch compares an integer with cases. Without break control falls through.
Example
#include <stdio.h>
int main(void) {
int d = 2;
switch (d) {
case 1: printf("one\n"); break;
case 2: printf("two\n");
case 3: printf("three\n"); break;
default: printf("other\n");
}
return 0;
}Result
two three
Exercise
Stop fall through.
case 1: x(); ;
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.