Java break [flag]; with continue [flag]; Difference

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.