source:
src/Tests/LabelledExit.c
@
a3e7d34
Last change on this file since a3e7d34 was 2871210, checked in by , 9 years ago | |
---|---|
|
|
File size: 2.2 KB |
Rev | Line | |
---|---|---|
[51b7345] | 1 | int main() { |
[2871210] | 2 | int i; |
3 | int x, y; | |
[51b7345] | 4 | |
[2871210] | 5 | x = 0; y = 0; |
[51b7345] | 6 | |
[2871210] | 7 | // block, labelled exits |
[51b7345] | 8 | |
9 | Block: { | |
[2871210] | 10 | if ( x == y ) { |
11 | for ( ; i < y; ) { | |
12 | y += 1; | |
13 | if ( y < 10 ) break Block; | |
14 | } | |
15 | } | |
16 | } | |
[51b7345] | 17 | |
[2871210] | 18 | // loops, labelled exits |
[51b7345] | 19 | |
20 | w1: while ( y == 10 ); | |
21 | ||
22 | w2: while ( x < 10 ) { | |
[2871210] | 23 | while (y < 5 ) { |
24 | if ( y == 3 ) break w2; | |
25 | } | |
26 | x += 1; | |
27 | } | |
[51b7345] | 28 | |
29 | A: for ( i = 0; i < 10; i += 1 ) { | |
[2871210] | 30 | B: for ( i = 0; i < 10; i += 1 ) { |
31 | C: for ( i = 0; i < 10; i += 1 ) { | |
32 | goto A; | |
33 | goto B; | |
34 | goto C; | |
35 | continue A; | |
36 | continue B; | |
37 | continue C; | |
38 | continue; | |
39 | break A; | |
40 | break B; | |
41 | break C; | |
42 | break; | |
43 | } | |
44 | } | |
45 | } | |
[51b7345] | 46 | |
47 | D: for ( ;; ) { | |
[2871210] | 48 | break D; |
49 | continue D; | |
50 | } | |
[51b7345] | 51 | |
[2871210] | 52 | Z : i += 1; |
53 | goto Z; | |
[51b7345] | 54 | X: Y: for ( ;; ) { |
[2871210] | 55 | i += 1; |
56 | if ( i > 5 ) continue X; | |
57 | if ( i < 5 ) break X; | |
58 | if ( i < 5 ) break Y; | |
59 | break; | |
60 | } | |
[51b7345] | 61 | XX: for ( ;; ) { |
[2871210] | 62 | YY: for ( ;; ) { |
63 | ZZ: for ( ;; ) { | |
64 | i += 1; | |
65 | if ( i > 5 ) continue XX; | |
66 | if ( i < 5 ) continue YY; | |
67 | if ( i < 5 ) continue ZZ; | |
68 | if ( i > 5 ) break XX; | |
69 | if ( i < 5 ) break YY; | |
70 | if ( i < 5 ) break ZZ; | |
71 | break; | |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | for ( ;; ) ; | |
77 | for ( int i = 0 ;; ) ; | |
78 | for ( ; i < 0; ) ; | |
79 | for ( ; ; i += 1 ) ; | |
[51b7345] | 80 | L0: L1: L2: L3: L4: L5: L6: L7: L8: L9: |
81 | L10: L11: L12: L13: L14: L15: L16: L17: L18: L19: | |
82 | L20: L21: L22: L23: L24: L25: L26: L27: L28: L29: | |
83 | L31: L32: L33: L34: | |
[2871210] | 84 | for ( ;; ) { |
85 | break L0; | |
86 | } | |
[51b7345] | 87 | |
[2871210] | 88 | // switch/choose, labelled exits |
[51b7345] | 89 | |
90 | Switch: switch ( i ) { | |
[2871210] | 91 | default: |
92 | i += 1; | |
93 | case 0: | |
94 | i += 1; | |
95 | break Switch; | |
96 | case 1: | |
97 | switch ( i ) { | |
98 | case 0: | |
99 | break Switch; | |
100 | default: | |
101 | ; break; | |
102 | } | |
103 | } | |
[51b7345] | 104 | |
105 | Choose: choose ( i ) { | |
[2871210] | 106 | default: |
107 | i += 1; | |
108 | case 0: | |
109 | i += 1; | |
110 | break Choose; | |
111 | case 1: | |
112 | choose ( i ) { | |
113 | case 0: | |
114 | break; | |
115 | default: | |
116 | break Choose; | |
117 | } | |
118 | fallthru; | |
119 | case 2: | |
120 | i += 1; | |
121 | } | |
[51b7345] | 122 | |
[2871210] | 123 | // computed goto |
124 | { | |
125 | void *array[] = { &&foo, &&bar, &&hack }; | |
126 | foo: bar: hack: | |
127 | &&foo; | |
128 | &&bar; | |
129 | goto *array[i]; | |
130 | } | |
[51b7345] | 131 | |
132 | #if 0 | |
133 | Q: if ( i > 5 ) { | |
[2871210] | 134 | i += 1; |
135 | break Q; | |
136 | } else | |
137 | i += 1; | |
[51b7345] | 138 | #endif |
139 | } | |
[2871210] | 140 | |
141 | // Local Variables: // | |
142 | // tab-width: 4 // | |
143 | // compile-command: "cfa LabelledExit.c" // | |
144 | // End: // |
Note: See TracBrowser
for help on using the repository browser.