-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8_nested_loop_Lable.dart
87 lines (79 loc) · 1.26 KB
/
8_nested_loop_Lable.dart
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
85
86
87
void main(){
// if want to stop prog after 2 2
// but it will not work beacuse break and continue always work in nearer loop so we will use label
print("without LABLE");
for(var i = 1; i <= 3 ; i++){
for(var j=1 ; j <= 3 ; j++){
if(i==2 && j==2){
break;
}
print("$i $j");
}
}
print("with LABLE");
// anyLable: forloop
// remember there is a space after :_ .
OuterLoop: for(var i = 1; i <= 3 ; i++){
InnerLoop: for(var j=1 ; j <= 3 ; j++){
if(i==2 && j==2){
break OuterLoop;
}
print("$i $j");
}
}
// continue
// if u just want to skip 2 2 and 2 3 in prog
print(" ");
print("without LABLE");
for(var i = 1; i <= 3 ; i++){
for(var j=1 ; j <= 3 ; j++){
if(i==2 && j==2){
continue;
}
print("$i $j");
}
}
print("with LABLE");
// anyLable: forloop
// remember there is a space after :_ .
Outer: for(var i = 1; i <= 3 ; i++){
Inner: for(var j=1 ; j <= 3 ; j++){
if(i==2 && j==2){
continue Outer;
}
print("$i $j");
}
}
}
/* result
without LABLE
1 1
1 2
1 3
2 1
3 1
3 2
3 3
with LABLE
1 1
1 2
1 3
2 1
without LABLE
1 1
1 2
1 3
2 1
2 3
3 1
3 2
3 3
with LABLE
1 1
1 2
1 3
2 1
3 1
3 2
3 3
*/