1/*
2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16function labeledTest01(): int {
17    let value: int = 0;
18    let result: int = 0;
19
20    label1:
21    for (let i = 0; i < 10; i++) {
22        switch (value) {
23            case 0:
24            case 1:
25                result += 2;
26                ++i;
27                continue label1;
28            case 2:
29                result = 1;
30                break;
31            default:
32                result = 3400;
33        }
34    }
35
36    return result;
37}
38
39function labeledTest02(): int {
40    let value: int = 0;
41    let result: int = 0;
42
43    for (let i = 0; i < 10; i++) {
44        label1:
45        for (let j = 0; j < 10; j++) {
46            if (i + j > 10) {
47                result += i * j;
48                break label1;
49            } else {
50                continue label1;
51            }
52        }
53    }
54
55    return result;
56}
57
58function labeledTest03(): int {
59    let result: int = 1;
60    let i = 0;
61    let j = 0;
62
63    while (i < 100) {
64
65        label1:
66        for (let k = 0; k < 5; k++) {
67            if (result < 10) {
68                result += (k + 1) * (i + 1);
69
70                ++i;
71                k = i;
72                break label1;
73            }
74        }
75
76        label2:
77        for (let l = 0; l < 79; l++) {
78            result -= l / (i + 2);
79
80            if (result > 13) {
81                break label2;
82            }
83        }
84
85        i++;
86
87        return result;
88    }
89
90    return result;
91}
92
93function labeledTest04(): int {
94    let result: int = 0;
95    let i = 0;
96
97    label1:
98    do {
99        i = i + 1;
100        result = result + i;
101        if (result > 10000) {
102            break label1;
103        }
104
105    } while (i < 142);
106
107    return result - 11;
108}
109
110function labeledTest05(): int {
111    let h = 0;
112    loop1:
113    for (let i = 0; i < 3; i++) {
114        loop2:
115        for (let j = 0; j < 3; j++) {
116            if (i == 1 && j == 1) {
117                h += 20;
118                break loop1;
119            } else {
120                h += 100;
121                continue loop2;
122            }
123        }
124    }
125    return h;
126}
127
128function main(): void {
129    let test1 = labeledTest01();
130    assert test1 == 10;
131
132    let test2 = labeledTest02();
133    assert test2 == 200;
134
135    let test3 = labeledTest03();
136    assert test3 == -999;
137
138    let test4 = labeledTest04();
139    assert test4 == 10000;
140
141    let test5 = labeledTest05();
142    assert test5 == 420;
143}
144