C examples for Statement:switch
The general way of describing the switch statement is as follows:
switch(integer_expression) { case constant_expression_1: statements_1; break; .... case constant_expression_n: statements_n; break; default: statements; break; }
Here's an example:
#include <stdio.h> int main(void) { enum Weekday {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}; enum Weekday today = Wednesday; switch(today) {//from ww w .ja v a 2 s .c om case Sunday: printf("Today is Sunday."); break; case Monday: printf("Today is Monday."); break; case Tuesday: printf("Today is Tuesday."); break; case Wednesday: printf("Today is Wednesday."); break; case Thursday: printf("Today is Thursday."); break; case Friday: printf("Today is Friday."); break; case Saturday: printf("Today is Saturday."); break; } return 0; }