-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnested_switch.cpp
56 lines (47 loc) · 1.12 KB
/
nested_switch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// clang-format off
/*****************************************************************//**
* \file nested_switch.cpp
* \brief g++ nested_switch.cpp -o nested_switch.exe
* ./nested_switch.exe
*
* \author Xuhua Huang
* \date November 06, 2020
*********************************************************************/
// clang-format on
#include <iostream>
int main(void) {
int x = 1, y = 1;
std::cout << "Initially, X is: " << x << "\n"
<< "Y is: " << y << "\n";
int m, n;
m = n = 1;
switch (m) {
case 0: // this case is ignored
x = x * 2;
case 1: // executed
{
switch (n) {
case 1: // executed
x = x * 2;
case 2:
y = y * 2; // executed
break;
case 3:
x++;
}
}
case 2: // no break on previous case, executed
x++;
y++;
case 3: // no break in previous case, executed
x *= 2;
y *= 2;
break;
default:
x++;
y++;
}
std::cout << "\nX is now: " << x << "\n"
<< "Y is now: " << y << "\n";
return 0;
}