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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
| package main
import "fmt"
func continue1() {
OuterLoop:
for i := 0; i < 2; i++ {
for j := 0; j < 5; j++ {
if j == 3 {
fmt.Println(i, j)
continue OuterLoop
}
}
}
}
func continue2() {
OuterLoop:
for i := 0; i < 2; i++ {
for j := 0; j < 5; j++ {
switch j {
case 3:
fmt.Println(i, j)
continue OuterLoop
}
}
}
}
func continue3() {
for i := 0; i < 2; i++ {
for j := 0; j < 5; j++ {
if j == 3 {
fmt.Println(i, j)
continue
}
}
}
}
func continue4() {
for i := 0; i < 2; i++ {
for j := 0; j < 5; j++ {
switch j {
case 3:
fmt.Println(i, j)
continue
}
}
}
}
func main() {
fmt.Println("continue 语句 仅用于for语句中")
fmt.Println("continue + 标签的情况 --------------")
fmt.Println("continue1() --------------")
continue1()
fmt.Println("continue2() --------------")
continue2()
fmt.Println("continue 没有标签的情况 --------------")
fmt.Println("continue3() --------------")
continue3()
fmt.Println("continue4() --------------")
continue4()
}
// Output:
//continue 语句 仅用于for语句中
//continue + 标签的情况 --------------
//continue1() --------------
//0 3
//1 3
//continue2() --------------
//0 3
//1 3
//continue 没有标签的情况 --------------
//continue3() --------------
//0 3
//1 3
//continue4() --------------
//0 3
//1 3
|