{"id":709,"date":"2023-03-23T21:50:23","date_gmt":"2023-03-23T13:50:23","guid":{"rendered":""},"modified":"2023-03-23T21:50:23","modified_gmt":"2023-03-23T13:50:23","slug":"Java Break\u8bed\u53e5","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/709.html","title":{"rendered":"Java Break\u8bed\u53e5"},"content":{"rendered":"
\n
jump-statement;
break<\/span>;
<\/span><\/code><\/pre>\n<\/p><\/div>\n
<\/p>\n
\u5e26\u5faa\u73af\u7684Java Break\u8bed\u53e5<\/h2>\n\n \u793a\u4f8b: <\/strong>\n <\/div>\n\n public<\/span> class break<\/span>Example {
public<\/span> static<\/span> void<\/span> main(String[] args) {
\/\/using for<\/span> loop
for<\/span> (int i = 1; i <= 10; i++) {
if<\/span> (i == 5) {
\/\/break<\/span>ing the loop
break<\/span>;
}
System.out.println<\/span><\/span>(i);
}
}
}
<\/span><\/code><\/pre>\n<\/p><\/div>\n\n \u8f93\u51fa:\n <\/div>\n\n\n 1
2
3
4
<\/span><\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n\u5e26\u6709\u5185\u90e8\u5faa\u73af\u7684Java Break\u8bed\u53e5<\/h2>\n\n \u4ec5\u5f53\u60a8\u5728\u5185\u90e8\u5faa\u73af\u4e2d\u4f7f\u7528break\u8bed\u53e5\u65f6\uff0c\u5b83\u624d\u4f1a\u4e2d\u65ad\u5185\u90e8\u5faa\u73af\u3002\n <\/div>\n\n \u793a\u4f8b: <\/strong>\n <\/div>\n\n public<\/span> class break<\/span>Example2 {
public<\/span> static<\/span> void<\/span> main(String[] args) {
\/\/outer<\/span> loop
for<\/span> (int i = 1; i <= 3; i++) {
\/\/inner loop
for<\/span> (int j = 1; j <= 3; j++) {
if<\/span> ((i == 2) && (j == 2)) {
\/\/using break<\/span> statement inside the inner loop
break<\/span>;
}
System.out.println<\/span><\/span>(i + \" \"<\/span> + j);
}
}
}
}
<\/span><\/code><\/pre>\n<\/p><\/div>\n\n \u8f93\u51fa:\n <\/div>\n\n\n 1 1
1 2
1 3
2 1
3 1
3 2
3 3 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n\u6807\u6709For\u5faa\u73af\u7684Java Break\u8bed\u53e5<\/h2>\n\n \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5e26\u6709\u6807\u7b7e\u7684break\u8bed\u53e5\u3002\u6b64\u529f\u80fd\u662f\u4eceJDK 1.5\u5f00\u59cb\u5f15\u5165\u7684\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u73b0\u5728\u53ef\u4ee5\u6253\u7834Java\u4e2d\u7684\u4efb\u4f55\u5faa\u73af\uff0c\u65e0\u8bba\u662f\u5916\u90e8\u5faa\u73af\u8fd8\u662f\u5185\u90e8\u5faa\u73af\u3002\n <\/div>\n\n \u793a\u4f8b: <\/strong>\n <\/div>\n\n public<\/span> class break<\/span>Example3 {
public<\/span> static<\/span> void<\/span> main(String[] args) {
aa:for<\/span> (int i = 1; i <= 3; i++) {
bb:for<\/span> (int j = 1; j <= 3; j++) {
if<\/span> ((i == 2) && (j == 2)) {
\/\/using break<\/span> statement with label
break<\/span> aa;
}
System.out.println<\/span><\/span>(i + \" \"<\/span> + j);
}
}
}
}
<\/span><\/code><\/pre>\n<\/p><\/div>\n\n \u8f93\u51fa:\n <\/div>\n\n\n 1 1
1 2
1 3
2 1
<\/span><\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n while\u5faa\u73af\u4e2d\u7684Java Break\u8bed\u53e5<\/h2>\n\n \u793a\u4f8b: <\/strong>\n <\/div>\n\n public<\/span> class break<\/span>while<\/span>Example {
public<\/span> static<\/span> void<\/span> main(String[] args) {
\/\/while<\/span> loop
int i = 1;
while<\/span> (i <= 10) {
if<\/span> (i == 5) {
\/\/using break<\/span> statement
i++;
break<\/span>; \/\/it will break<\/span> the loop
}
System.out.println<\/span><\/span>(i);
i++;
}
}
}
<\/span><\/code><\/pre>\n<\/p><\/div>\n\n \u8f93\u51fa:\n <\/div>\n\n\n 1
2
3
4
<\/span><\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n do-while\u5faa\u73af\u4e2d\u7684Java Break\u8bed\u53e5<\/h2>\n\n \u793a\u4f8b: <\/strong>\n <\/div>\n\n public<\/span> class break<\/span>do<\/span>while<\/span>Example {
public<\/span> static<\/span> void<\/span> main(String[] args) {
\/\/declaring var<\/span>iable
int i = 1;
\/\/do<\/span>-while<\/span> loop
do<\/span> {
if<\/span> (i == 5) {
\/\/using break<\/span> statement
i++;
break<\/span>; \/\/it will break<\/span> the loop
}
System.out.println<\/span><\/span>(i);
i++;
} while<\/span> (i <= 10);
}
}
<\/span><\/code><\/pre>\n<\/p><\/div>\n\n \u8f93\u51fa:\n <\/div>\n\n\n 1
2
3
4 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n\u5e26\u6709Switch\u7684Java Break\u8bed\u53e5<\/h2>\n\n \u8981\u4e86\u89e3\u5e26\u6709switch\u8bed\u53e5\u7684\u793a\u4f8b\uff0c\u8bf7\u8bbf\u95ee\u6b64\u5904:
\n Java Switch\u58f0\u660e\u3002\n <\/div>\n <\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Java Break\u8bed\u53e5zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111],"tags":[],"class_list":["post-709","post","type-post","status-publish","format-standard","hentry","category-java-jichu"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/709"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=709"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/709\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}