• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 fors(): void {
17  for (let i = 1; i < 5; i++) continue;
18  let j = 1;
19  for (j = 1; i < 5; i++) continue;
20  // Valid but must be fixed in grammar
21  // for (;;) break;
22  for (let i = 1, j = 3; i + j < 30; i += j) {
23    continue;
24  }
25}
26
27function whiles(): void {
28  while (false) {
29  }
30
31  while (true) break;
32}
33
34function dowhiles(): void {
35  let i = 0;
36  do
37    i += 1;
38  while (i < 30);
39
40  do {
41    i *= -1
42  } while (i != 30);
43}
44
45// see 6.9
46function labeledbreak(): void {
47  loop1:
48  for (let i = 1; i < 5; i++) {
49    loop2:
50    for (let j = 1; j < 5; j++) {
51      break loop1;
52    }
53  }
54}
55
56// see 6.10
57function labeledcontinue(): void {
58  loop1:
59  for (let i = 1; i < 5; i++) {
60    loop2:
61    for (let j = 1; j < 5; j++) {
62      continue loop1;
63    }
64  }
65}
66