C++ case Keyword
Example
Calculate the weekday name:
int day = 4;
switch (day) {
case 1:
cout << "Monday";
break;
case 2:
cout << "Tuesday";
break;
case 3:
cout << "Wednesday";
break;
case 4:
cout << "Thursday";
break;
case 5:
cout << "Friday";
break;
case 6:
cout << "Saturday";
break;
case 7:
cout << "Sunday";
break;
}
// Outputs "Thursday" (day 4)
Definition and Usage
The case
keyword marks a block of code in a switch
statement.
Related Pages
Read more about the switch statement in our C++ Switch Tutorial.