break [flag];
Directly ends the loop that falls to the flag layer
no1:for (int i=0; i<100; i++) {
for (int j=0; j<10; J + +) {
sum = i*j;
if (sum>500) {
SYSTEM.OUT.PRINTLN (i+ "*" +j+ "=" +sum);
Break NO1;
}
}
}
For example: When sum>500, exit the two-layer for loop;
continue [flag];
Exit this loop of the marker layer
no1:for (int i=0; i<100; i++) {
for (int j=0; j<10; J + +) {
sum = i*j;
if (sum>500) {
SYSTEM.OUT.PRINTLN (i+ "*" +j+ "=" +sum);
Continue NO1;
}
}
}
For example: When i=72, j=7 sum>500, go directly out of the situation when i=72, (then i=72, j=8 and i=72, j= 9) directly from the i=73 cycle
Input:
56*9=504
57*9=513
58*9=522
59*9=531
60*9=540
61*9=549
62*9=558
63*8=504
64*8=512
65*8=520
66*8=528
67*8=536
68*8=544
69*8=552
70*8=560
71*8=568
72*7=504
73*7=511
74*7=518
75*7=525
76*7=532
77*7=539
78*7=546
79*7=553
80*7=560
81*7=567
82*7=574
83*7=581
84*6=504
85*6=510
86*6=516
87*6=522
88*6=528
89*6=534
90*6=540
91*6=546
92*6=552
93*6=558
94*6=564
95*6=570
96*6=576
97*6=582
98*6=588
99*6=594
Java break [flag]; with continue [flag]; Difference