Switch statement in C++
Level 3177 keystrokes
switch compares day with each case label and runs the matching case. day is 3, so "Wed" is printed.
C++ code
1int day = 3;// switch jumps to the case label equal to day2switch (day) { // break leaves the switch; without it, execution would fall through to the next case3 case 1: cout << "Mon" << endl; break;4 case 2: cout << "Tue" << endl; break; // day is 3, so only this case runs and prints Wed5 case 3: cout << "Wed" << endl; break; // default runs when no case matches6 default: cout << "Other" << endl;7}Output
Wed
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 16;× 8"× 8:× 4(× 1)× 1{× 1}× 1=× 1