1switch (n)
2{
3 case 1: // code to be executed if n = 1;
4 break;
5 case 2: // code to be executed if n = 2;
6 break;
7 default: // code to be executed if n doesn't match any cases
8}
1#include <iostream>
2using namespace std;
3int main(){
4 int num = 5;
5 switch(num + 2) {
6 case 1:
7 cout << "Case1: Value is: " << num << endl;
8 case 2:
9 cout << "Case2: Value is: " << num << endl;
10 case 3:
11 cout << "Case3: Value is: " << num << endl;
12 default:
13 cout << "Default: Value is: " << num << endl;
14 }
15 return 0;
16}
1switch (val)
2{
3case VAL:
4{
5 // This will work
6 int newVal = 42;
7 break;
8}
9case ANOTHER_VAL:
10...
11break;
12}
13