switch is used when you want to compare one value against several cases. For things like menu options, day numbers, or status codes, if...else it can be cleaner than writing a long chain of these.
c
#include <stdio.h>
int main() {
int day = 4;
switch (day) {
case 1:
printf("Monday");
break;
case 4:
printf("Thursday");
break;
default:
printf("Unknown day");
}
return 0;
}day's value is 4, so case 4's code runs. break then exits out of the switch.
You should see
ThursdayInfo
default is the fallback that runs when nothing matches any case. It comes in handy when you're handling user input.