{"id":8120,"date":"2024-06-22T08:01:01","date_gmt":"2024-06-22T00:01:01","guid":{"rendered":""},"modified":"2024-06-22T08:01:01","modified_gmt":"2024-06-22T00:01:01","slug":"\u7b2c\u4e09\u7ae0 \u6d41\u7a0b\u63a7\u5236_\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u56fe","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8120.html","title":{"rendered":"\u7b2c\u4e09\u7ae0 \u6d41\u7a0b\u63a7\u5236_\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u56fe"},"content":{"rendered":"
\u987a\u5e8f\u7ed3\u6784\u3001\u9009\u62e9\u7ed3\u6784\u548c\u5faa\u73af\u7ed3\u6784\u662f\u7ed3\u6784\u5316\u7a0b\u5e8f\u8bbe\u8ba1\u76843\u79cd\u57fa\u672c\u7ed3\u6784\uff0c\u662f\u5404\u79cd\u590d\u6742\u7a0b\u5e8f\u7684\u57fa\u672c\u6784\u9020\u5355\u5143\u3002\u56fe3.1\u5c55\u793a\u4e86\u8fd93\u79cd\u7a0b\u5e8f\u7ed3\u6784\u7684\u57fa\u672c\u7406\u5ff5\uff0c\u5176\u4e2d\uff0c\u7b2c\u4e00\u5e45\u56fe\u662f\u987a\u5e8f\u7ed3\u6784\u7684\u6d41\u7a0b\u56fe\uff0c\u5b83\u5c31\u662f\u6309\u7167\u4e66\u5199\u987a\u5e8f\u6267\u884c\u7684\u8bed\u53e5\u6784\u6210\u7684\u7a0b\u5e8f\u6bb5\uff1b\u7b2c\u4e8c\u5e45\u56fe\u662f\u9009\u62e9\u7ed3\u6784\u7684\u6d41\u7a0b\u56fe\uff0c\u5b83\u4e3b\u8981\u6839\u636e\u8f93\u5165\u6570\u636e\u548c\u4e2d\u95f4\u7ed3\u679c<\/p>\n
<\/p>\n
\u4f8b3.2\u4e24\u79cd\u60c5\u51b5\u90fd\u662f\u6b63\u786e\u7684<\/p>\n
<\/p>\n
<\/p>\n
<\/p>\n
if...else if\u591a\u5206\u652f\u8bed\u53e5\u7528\u4e8e\u9488\u5bf9\u67d0\u4e00\u4e8b\u4ef6\u7684\u591a\u79cd\u60c5\u51b5\u8fdb\u884c\u5904\u7406\u3002\u901a\u5e38\u8868\u73b0\u4e3a\u201c\u5982\u679c\u6ee1\u8db3\u67d0\u79cd\u6761\u4ef6\uff0c\u5c31\u8fdb\u884c\u67d0\u79cd\u5904\u7406\uff1b\u5982\u679c\u6ee1\u8db3\u53e6\u4e00\u79cd\u6761\u4ef6\uff0c\u5219\u8fdb\u884c\u53e6\u4e00\u79cd\u5904\u7406\u201d<\/p>\n
<\/p>\n
<\/p>\n
<\/p>\n
<\/p>\n
<\/p>\n
\u524d\u9762\u8bb2\u8fc7\u4e09\u79cd\u5f62\u5f0f\u7684\u6761\u4ef6\u8bed\u53e5\uff0c\u8fd9\u4e09\u79cd\u5f62\u5f0f\u7684\u6761\u4ef6\u8bed\u53e5\u90fd\u53ef\u4ee5\u5d4c\u5957\u6761\u4ef6\u8bed\u53e5\u3002\u4f8b\u5982\uff0c\u5728\u7b2c\u4e00\u5f62\u5f0f\u7684\u6761\u4ef6\u8bed\u53e5\u4e2d\u5d4c\u5957\u7b2c\u4e8c\u79cd\u5f62\u5f0f\u7684\u6761\u4ef6\u8bed\u53e5\u3002\u5f62\u5f0f\u5982\u4e0b\uff1a\\<\/p>\n
<\/p>\n
\u5728\u7b2c\u4e8c\u79cd\u5f62\u5f0f\u7684\u6761\u4ef6\u8bed\u53e5\u4e2d\u5d4c\u5957\u7b2c\u4e8c\u79cd\u5f62\u5f0f\u7684\u6761\u4ef6\u8bed\u53e5\u3002\u5f62\u5f0f\u5982\u4e0b\uff1a<\/p>\n
<\/p>\n
\u6761\u4ef6\u8bed\u53e5\u53ef\u4ee5\u6709\u591a\u79cd\u5d4c\u5957\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u8981\u8fdb\u884c\u8bbe\u8ba1\uff0c\u4f46\u4e00\u5b9a\u8981\u6ce8\u610f\u903b\u8f91\u5173\u7cfb<\/p>\n
<\/p>\n
<\/p>\n
switch \u8bed\u53e5\u9996\u5148\u8ba1\u7b97\u53c2\u6570\u7684\u503c,\u5982\u679c\u53c2\u6570\u7684\u503c\u548c\u67d0\u4e2acase \u540e\u9762\u7684\u5e38\u91cf\u8868\u8fbe\u5f0f\u76f8\u540c,\u5219\u6267\u884c\u8be5 case\u543e\u53e5\u540e\u7684\u82e5\u5e72\u4e2a\u8bed\u53e5\uff0c\u76f4\u5230\u9047\u5230 break \u8bed\u53e5\u4e3a\u6b62\u3002\u6b64\u65f6\u5982\u679c\u8be5 case \u8bed\u53e5\u4e2d\u6ca1\u6709 break \u8bed\u53e5\uff0c\u5c06\u7ee7\u7eed\u6267\u884c\u540e\u9762 case \u4e2d\u7684\u82e5\u5e72\u4e2a\u8bed\u53e5\uff0c\u76f4\u5230\u9047\u5230 break \u8bed\u53e5\u4e3a\u6b62\u3002\u82e5\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u5e38\u91cf\u8868\u8fbe\u5f0f\u4e0e\u53c2\u6570\u7684\u503c\u76f8\u540c\uff0c\u5219\u6267\u884c default \u540e\u9762\u7684\u8bed\u53e5\u3002
break \u7684\u4f5c\u7528\u662f\u8df3\u51fa\u6574\u4e2a switch \u8bed\u53e5\u3002
default \u8bed\u53e5\u662f\u53ef\u4ee5\u4e0d\u5199\u7684\uff0c\u5982\u679c\u5b83\u4e0d\u5b58\u5728\uff0c\u800c\u4e14 switch \u8bed\u53e5\u4e2d\u8868\u8fbe\u5f0f\u7684\u503c\u4e0d\u4e0e\u4efb\u4f55 case \u7684\u5e38\u91cf\u503c\u76f8\u540c\uff0cswitch \u5219\u4e0d\u505a\u4efb\u4f55\u5904\u7406\u3002<\/p>\n
\u4ee5\u4e00\u4e2a\u8f83\u7b80\u5355\u660e\u4e86\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u201c\u591a\u9009\u4e00\u201d\u7684\u9009\u62e9\u3002 \u8bed\u6cd5\u5982\u4e0b
<\/p>\n
switch(\u7528\u4e8e\u5224\u65ad\u7684\u53c2\u6570){ case \u5e38\u91cf\u8868\u8fbe\u5f0f1\uff1a\u8bed\u53e51\uff1b[break\uff1b] case \u5e38\u91cf\u8868\u8fbe\u5f0f2\uff1a\u8bed\u53e52\uff1b[break\uff1b]...... case \u5e38\u91cf\u8868\u8fbe\u5f0fn\uff1a\u8bed\u53e5n;[break;] default\uff1a\u8bed\u53e5n+1\uff1b[break;] }<\/code><\/pre>\n switch\u8bed\u53e5\u9996\u5148\u8ba1\u7b97\u53c2\u6570\u7684\u503c\uff0c\u5982\u679c\u53c2\u6570\u7684\u503c\u548c\u67d0\u4e2acase\u540e\u9762\u7684\u5e38\u91cf\u8868\u8fbe\u5f0f\u76f8\u540c\uff0c\u5219\u6267\u884c\u8be5case\u8bed\u53e5\u540e\u7684\u82e5\u5e72\u4e2a\u8bed\u53e5\uff0c\u76f4\u5230\u9047\u5230break\u8bed\u53e5\u4e3a\u6b62\u3002\u6b64\u65f6\u5982\u679c\u8be5case\u8bed\u53e5\u4e2d\u6ca1\u6709break\u8bed\u53e5\uff0c\u5c06\u7ee7\u7eed\u6267\u884c\u540e\u9762case\u4e2d\u7684\u82e5\u5e72\u4e2a\u8bed\u53e5\uff0c\u76f4\u5230\u9047\u5230break\u8bed\u53e5\u4e3a\u6b62\u3002\u82e5\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u5e38\u91cf\u8868\u8fbe\u5f0f\u4e0e\u53c2\u6570\u7684\u503c\u76f8\u540c\uff0c\u5219\u6267\u884cdefault\u540e\u9762\u7684\u8bed\u53e5\u3002
break\u7684\u4f5c\u7528\u662f\u8df3\u51fa\u6574\u4e2aswitch\u8bed\u53e5\u3002
default\u8bed\u53e5\u662f\u53ef\u4ee5\u4e0d\u5199\u7684\uff0c\u5982\u679c\u5b83\u4e0d\u5b58\u5728\uff0c\u800c\u4e14switch\u8bed\u53e5\u4e2d\u8868\u8fbe\u5f0f\u7684\u503c\u4e0d\u4e0e\u4efb\u4f55case\u7684\u5e38\u91cf\u503c\u76f8\u540c\uff0cswitch\u5219\u4e0d\u505a\u4efb\u4f55\u5904\u7406\u3002switch\u8bed\u53e5\u7684\u6267\u884c\u6d41\u7a0b\u5982\u56fe3.11\u6240\u793a\u3002
<\/p>\n
public class GetSwitch { public static void main(String[] args) { int week=2;\/\/\u5b9a\u4e49int\u578b\u53d8\u91cfweek switch (week) { case 1:\/\/\u5b9a\u4e49case\u8bed\u53e5\u4e2d\u5e38\u91cf\u4e3a1 System.out.println(\"Monday\"); break; case 2:\/\/\u5b9a\u4e49case\u8bed\u53e5\u4e2d\u5e38\u91cf\u4e3a2 System.out.println(\"Tuesday\"); break; case 3:\/\/\u5b9a\u4e49case\u8bed\u53e5\u4e2d\u5e38\u91cf\u4e3a3 System.out.println(\"Wednesday\"); break; case 4:\/\/\u5b9a\u4e49case\u8bed\u53e5\u4e2d\u5e38\u91cf\u4e3a4 System.out.println(\"Thursday\"); break; case 5:\/\/\u5b9a\u4e49case\u8bed\u53e5\u4e2d\u5e38\u91cf\u4e3a5 System.out.println(\"Friday\"); break; case 6:\/\/\u5b9a\u4e49case\u8bed\u53e5\u4e2d\u5e38\u91cf\u4e3a6 System.out.println(\"Saturday\"); break; case 7:\/\/\u5b9a\u4e49case\u8bed\u53e5\u4e2d\u5e38\u91cf\u4e3a7 System.out.println(\"Sunday\"); break; default: System.out.println(\"Sorry,I don't Know\"); } } }<\/code><\/pre>\n <\/p>\n
\u4f8b3.8\u521b\u5efa\u6210\u7ee9\u7c7b\uff0c\u4f7f\u7528Scanner\u7c7b\u5728\u63a7\u5236\u53f0\u8f93\u5165\u5206\u6570\uff0c \u56fe3.12\u5224\u65ad\u661f\u671f\u5e76\u6253\u5370\u51fa\u8138 \u4f8b3.publ
\u7136\u540e\u7528switch\u8bed\u53e5\u5224\u65ad\u8f93\u5165\u7684\u5206\u6570\u5c5e\u4e8e\u54ea\u7c7b\u6210\u7ee9\u300210\u5206\u30019\u5206
\u5c5e\u4e8e\u4f18\uff0c8\u5206\u5c5e\u4e8e\u826f\uff0c7\u5206\u30016\u5206\u5c5e\u4e8e\u53ca\u683c\uff0c5\u5206\u30014\u5206\u30013\u5206\u30012\u5206\u30011\u5206\u30010\u5206\u5747\u4e3a\u4e0d\u53ca\u683c\u3002<\/h3>\n<\/pre>\n\n- \n<\/p>\n<\/li>\n<\/ol>\n
\u4f8b3.9 \u901a\u8fc7switch\u8bed\u53e5\u6839\u636e\u5b57\u7b26\u4e32str\u7684\u503c\uff0c\u8f93\u51fa\u4e0d\u540c\u7684\u63d0\u793a\u4fe1\u606f\u3002<\/h3>\n<\/pre>\n\n- \n<\/p>\n<\/li>\n<\/ol>\n
3.3\u5faa\u73af\u8bed\u53e5
\u5faa\u73af\u8bed\u53e5\u5c31\u662f\u5728\u6ee1\u8db3\u4e00\u5b9a\u6761\u4ef6\u7684\u60c5\u51b5\u4e0b\u53cd\u590d\u6267\u884c\u67d0\u4e00\u4e2a\u64cd\u4f5c\u3002\u5728Java\u4e2d\u63d0\u4f9b\u4e864\u79cd\u5e38\u7528\u7684\u5faa\u73af\u8bed\u53e5\uff0c\u5206\u522b\u662fwhile\u8bed\u53e5\u3001do...while \u8bed\u53e5\u3001for \u8bed\u53e5\u548c foreach \u8bed\u53e5\uff0c\u5176\u4e2d\uff0cforeach \u8bed\u53e5\u662f for \u8bed\u53e5\u7684\u7279\u6b8a\u7b80\u5316\u7248\u672c\u3002<\/h3>\n3.3.1 while\u5faa\u73af\u8bed\u53e5
While\u8bed\u53e5\u7684\u5faa\u73af\u65b9\u5f0f\u4e3a\u5229\u7528\u4e00\u4e2a\u6761\u4ef6\u6765\u63a7\u5236\u662f\u5426\u8981\u7ee7\u7eed\u53cd\u590d\u6267\u884c\u8fd9\u4e2a\u8bed\u53e5<\/h4>\n\u4f8b3.10\u5728\u9879\u76ee\u4e2d\u521b\u5efa\u7c7bCycle,\u5728\u4e3b\u65b9\u6cd5\u4e2d\u901a\u8fc7while\u5faa\u73af\u5c06\u6574\u65701\u2014100\u76f8\u52a0<\/h4>\n
<\/p>\n
3.2 do...while\u5faa\u73af\u8bed\u53e5
do...while \u5faa\u73af\u8bed\u53e5\u4e0e while \u5faa\u73af\u8bed\u53e5\u7c7b\u4f3c\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u533a\u522b\u662f while \u8bed\u53e5\u4e3a\u5148\u5224\u65ad\u6761\u4ef6\u662f\u5426\u6210\u7acb\u518d\u6267\u884c\u5faa\u73af\u4f53\uff0c\u800c do...while \u5faa\u73af\u8bed\u53e5\u5219\u5148\u6267\u884c\u4e00\u6b21\u5faa\u73af\u540e\uff0c\u518d\u5224\u65ad\u6761\u4ef6\u662f\u5426\u6210\u7acb\u3002\u4e5f\u5c31\u662f\u8bf4 do...while \u5faa\u73af\u8bed\u53e5\u4e2d\u201c{}\u201d\u4e2d\u7684\u7a0b\u5e8f\u6bb5\u81f3\u5c11\u8981\u88ab\u6267\u884c\u4e00\u6b21\u3002<\/h4>\n\u4f8b3.11 \u5728\u9879\u76ee\u4e2d\u521b\u5efa\u7c7bCycle
<\/h4>\n
<\/p>\n
<\/p>\n
3.3 while \u4e0e do...while \u6bd4\u8f83
\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u8d77\u59cb\u5faa\u73af\u6761\u4ef6\u4e0d\u6210\u7acb\u7684\u5faa\u73af\u8bed\u53e5\u6765\u89c2\u5bdf while \u548c do...while \u7684\u4e0d\u540c\u3002\u5c06\u53d8\u91cfi\u521d\u503c\u8bbe\u7f6e\u4e3a0\uff0c\u7136\u540e\u5faa\u73af\u8868\u8fbe\u5f0f\u8bbe\u7f6e\u4e3ai>1\uff0c\u663e\u7136\u5faa\u73af\u6761\u4ef6\u4e0d\u6210\u7acb\u3002\u5faa\u73af\u4f53\u6267\u884c\u7684\u662f\u5bf9\u53d8\u91cfj\u7684\u52a01\u8fd9\u7b97\uff0c\u901a\u8fc7\u8f93\u51fa\u53d8\u91cfj\u5728\u5faa\u73af\u524d\u7684\u503c\u548c\u5faa\u73af\u540e\u7684\u503c\u8fdb\u884c\u6bd4\u8f83\u3002<\/h2>\n\u4f8b3.12\u4f7f\u7528do..while\u5faa\u73af\u8f93\u51faJ\u7684\u503c<\/h4>\n
<\/p>\n
\u4f8b3.13\u4f7f\u7528while\u5faa\u73af\u8f93\u51faJ\u7684\u503c <\/h4>\n
<\/p>\n
\u4f8b3.14 \u4f7f\u7528for\u5faa\u73af\u5b8c\u62101\u2014100\u7684\u76f8\u52a0\u8fd0\u7b97 <\/h4>\npublic class AdditiveFor { public static void main(String[] args) { int sum=0; int i; for(i=1;i<=100;i++) { sum+=i; } System.out.println(\"the result :\"+sum); } }<\/code><\/pre>\n<\/p>\n
<\/p>\n
3.5 foreach\u8bed\u53e5
foreach \u8bed\u53e5\u662f for \u8bed\u53e5\u7684\u7279\u6b8a\u7b80\u5316\u7248\u672c\uff0c\u4f46\u662f foreach \u8bed\u53e5\u5e76\u4e0d\u80fd\u5b8c\u5168\u53d6\u4ee3 for \u8bed\u53e5\uff0c\u7136\u800c\u4efb\u4f55
foreach \u8bed\u53e5\u90fd\u53ef\u4ee5\u6539\u5199\u4e3a for \u8bed\u53e5\u7248\u672c\u3002foreach \u5e76\u4e0d\u662f\u4e00\u4e2a\u5173\u952e\u5b57\uff0c\u4e60\u60ef\u4e0a\u5c06\u8fd9\u79cd\u7279\u6b8a\u7684 for \u8bed\u53e5\u683c\u5f0f\u79f0\u4e4b\u4e3aforeach\u8bed\u53e5\u3002foreach \u8bed\u53e5\u5728\u904d\u5386\u6570\u7ec4\u7b49\u65b9\u9762\u4e3a\u7a0b\u5e8f\u5458\u63d0\u4f9b\u4e86\u5f88\u5927\u7684\u65b9\u4fbf\u3002<\/h3>\n \u4f8b3.15\u5728\u9879\u76ee\u4e2d\u521b\u5efa\u7c7bRepetition,\u5728\u4e3b\u65b9\u6cd5\u4e2d\u5b9a\u4e49\u4e00\u7ef4\u6570\u7ec4\uff0c\u5e76\u4f7f\u7528foreach\u8bed\u53e5\u904d\u5386<\/h3>\npublic class Repetition { public static void main(String[] args) { int arr[]= {7,10,1};\/\/\u58f0\u660e\u4e00\u7ef4\u6570\u7ec4 System.out.println(\"\u4e00\u7ef4\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5206\u522b\u4e3a\");\/\/\u8f93\u51fa\u4fe1\u606f for(int x :arr) { System.out.println(x); } } }<\/code><\/pre>\n<\/h4>\n\u4f8b3.16\u4f7f\u7528\u5d4c\u5957\u7684for\u5faa\u73af\u8f93\u51fa\u4e58\u6cd5\u53e3\u8bc0 <\/h4>\n
<\/p>\n
<\/p>\n
public class Multip { public static void main(String[] args) { int i, j;\/\/\u521b\u5efa\u4e24\u4e2a\u6574\u6570\u53d8\u91cf for(i=1; i<10;i++) {\/\/\u8f93\u51fa\u4e5d\u884c for(j=1;j<i+1;j++) {\/\/\u8f93\u51fa\u884c\u6570\u76f8\u7b49\u7684\u5217 System.out.print(j+\"*\"+i+\"=\"+i*j+\"\\t\"); } System.out.println();\/\/\u6362\u884c } } }<\/code><\/pre>\n <\/p>\n
3.4\u8df3\u8f6c\u8bed\u53e5
\u8df3\u8f6c\u8bed\u53e5\u5305\u542b\u4e24\u65b9\u9762\u7684\u5185\u5bb9\uff0c\u4e00\u65b9\u9762\u662f\u63a7\u5236\u5faa\u73af\u53d8\u91cf\u7684\u53d8\u5316\u65b9\u5f0f\uff0c\u4e5f\u5c31\u662f\u8ba9\u5faa\u73af\u5224\u65ad\u4e2d\u7684\u903b\u5173\u7cfb\u8868\u8fbe\u5f0f\u53d8\u6210false\uff0c\u4ece\u800c\u8fbe\u5230\u7ec8\u6b62\u5faa\u73af\u7684\u6548\u679c\uff1b\u4e00\u65b9\u9762\u662f\u63a7\u5236\u5faa\u73af\u7684\u8df3\u8f6c\u3002\u63a7\u5236\u5faa\u73af\u7684\u8df3\u8f6c\u6ee1\u7528\u5230break\u548cconinue \u4e24\u4e2a\u5173\u952e\u5b57\uff0c\u8fd9\u4e24\u6761\u8df3\u8f6c\u8bed\u53e5\u7684\u8df3\u8f6c\u6548\u679c\u4e0d\u540c\uff0cbreak\u662f\u4e2d\u65ad\u5faa\u73af\uff0cconting\u662f\u76f4\u63a5\u6267\u884c\u4e0b\u4e00\u6b21\u5faa\u73af\u3002
3.4.1 break \u8bed\u53e5
\u8425\u4e00\u89c6\uff0c\u8fd1\u89c6\u9891 \u4f7f\u7528break\u8bed\u53e5\u53ef\u4ee5\u8df3\u51faswitch\u7ed3\u6784\u3002\u5728\u5faa\u73af\u7ed3\u6784\u4e2d\uff0c\u540c\u6837\u4e5f\u53ef\u7528break\u8bed\u53e5\u8df3\u51fa\u5f53\u524d\u5faa\u73af\u4f53
\u4ece\u800c\u4e2d\u65ad\u5f53\u524d\u5faa\u73af\u3002
<\/h4>\n\u4f8b3.17\u8f93\u51fa1\u201420\u7684\u7b2c\u4e00\u4e2a\u5076\u6570\uff0c\u4f7f\u7528break\u8df3\u51fa<\/h4>\npublic class BreakTest { public static void main(String[] args) { for(int i=1; i<20;i++) { if(i%2==0) {\/\/\u5982\u679ci\u662f\u5076\u6570 System.out.println(i);\/\/\u8f93\u51fai\u7684\u503c break;\/\/\u8df3\u5165\u4e0b\u4e00\u5faa\u73af } } System.out.println(\"---end---\"); } }<\/code><\/pre>\n\u5faa\u73af <\/h4>\n
<\/p>\n
\u4f8b3.18\u5728\u5d4c\u5957\u7684\u5faa\u73af\u4e2d\u4f7f\u7528break,\u8df3\u51fa\u5185\u5c42\u5faa\u73af <\/h4>\npublic class BreakInside { public static void main(String[] args) { for(int i=0;i<3;i++) { for(int j=0;j<6;j++) { if(j==4) {\/\/\u5982\u679cJ\u7b49\u4e8e4\u7684\u65f6\u5019\u5c31\u7ed3\u675f\u5185\u5faa\u73af break; } System.out.println(\"i=\"+i+\" j=\"+j); } } } }<\/code><\/pre>\n<\/p>\n
\u4f8b3.19\u4f7f\u7528\u5e26\u6709\u6807\u7b7e\u7684break\u8df3\u51fa\u5916\u5c42\u5faa\u73af <\/h4>\npublic class BreakOutside { public static void main(String[] args) { Loop: for(int i=0;i<3;i++) {\/\/\u5728for\u5faa\u73af\u524d\u7528\u6807\u7b7e\u6807\u8bb0 for(int j=0;j<6;j++) { if(j==4) {\/\/\u5982\u679cJ\u7b49\u4e8e4\u7684\u65f6\u5019\u5c31\u7ed3\u675f\u5185\u5faa\u73af break Loop;\/\/\u8df3\u51faLoop\u6807\u7b7e\u6807\u8bb0\u7684\u5faa\u73af\u4f53 } System.out.println(\"i=\"+i+\" j=\"+j); } } } }<\/code><\/pre>\n<\/p>\n
3.4.2 continue \u8bed\u53e5
continue\u8bed\u53e5\u662f\u9488\u5bf9break\u8bed\u53e5\u7684\u8865\u5145\u3002continue\u4e0d\u662f\u7acb\u5373\u8df3\u51fa\u5faa\u73af\u4f53\uff0c\u800c\u662f\u8df3\u8fc7\u672c\u6b21\u5faa\u73af\u7ed3\u675f\u524d\u7684\u8bed\u53e5\uff0c\u56de\u5230\u5faa\u73af\u7684\u6761\u4ef6\u6d4b\u8bd5\u90e8\u5206\uff0c\u91cd\u65b0\u5f00\u59cb\u6267\u884c\u5faa\u73af\u3002\u5728for\u5faa\u73af\u8bed\u53e5\u4e2d\u9047\u5230continue\u8bed\u53e5\u540e\uff0c\u9996\u5148\u6267\u884c\u5faa\u73af\u7684\u589e\u91cf\u90e8\u5206\uff0c\u7136\u540e\u8fdb\u884c\u6761\u4ef6\u6d4b\u8bd5\u3002\u5728while\u548cdo..while\u5faa\u73af\u4e2d\uff0ccontinue\u8bed\u53e5\u4f7f\u63a7\u5236\u76f4\u63a5\u56de\u5230\u6761\u4ef6\u6d4b\u8bd5\u90e8\u5206\u3002
\u57283\u79cd\u5faa\u73af\u8bed\u53e5\u4e2d\u4f7f\u7528continue\u8bed\u53e5\u7684\u5f62\u5f0f\u5982\u56fe3.31\u6240\u793a\u3002<\/h4>\n
<\/p>\n
public class Continue { public static void main(String[] args) { for(int i=1;i<20;i++) { if(i%2!=0) {\/\/\u5982\u679ci\u4e0d\u662f\u5076\u6570 continue;\/\/\u8df3\u5165\u4e0b\u4e00\u5faa\u73af } System.out.println(i); } } }<\/code><\/pre>\n <\/p>\n
\u672c\u7ae0\u5c0f\u7ed3
\u672c\u7ae0\u4ecb\u7ecd\u4e86\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5(\u6761\u4ef6\u8bed\u53e5\u3001\u5faa\u73af\u8bed\u53e5\u548c\u8df3\u8f6c\u8bed\u53e5)\uff1b\u901a\u8fc7\u4f7f\u7528if\u4e0eswitch\u8bed\u53e5\uff0c\u53ef\u4ee5\u57fa\u4e8e\u5e03\u5c14\u7c7b\u578b\u7684\u6d4b\u8bd5\uff0c\u5c06\u4e00\u4e2a\u7a0b\u5e8f\u5206\u6210\u4e0d\u540c\u7684\u90e8\u5206\uff1a\u901a\u8fc7 while\u3001do..while \u5faa\u73af\u8bed\u53e5\u548cfor\u5faa\u73af\u8bed\u53e5\uff0c\u53ef\u4ee5\u8ba9\u7a0b\u5e8f\u7684\u4e00\u90e8\u5206\u91cd\u590d\u6267\u884c\uff0c\u76f4\u5230\u6ee1\u8db3\u67d0\u4e2a\u7ec8\u6b62\u5faa\u73af\u7684\u6761\u4ef6\uff1bfor\u548cwhile\u4e00\u6837\u662f\u5148\u5224\u65ad\u518d\u6267\u884c\uff0cfor\u5c31\u662f\u6765\u62ef\u6551\u5927\u5bb6\u7684\uff0cfor\u7528\u66f4\u52a0\u7b80\u5355\u7684\u8bed\u53e5\u89e3\u51b3\u4e86while\u7684\u95ee\u9898for(\u521d\u59cb\u5316\uff1b\u6761\u4ef61\uff1b\u6761\u4ef62){\u5faa\u73af\u4f53};\u4f7f\u7528\u8df3\u8f6c\u8bed\u53e5\u53ef\u4ee5\u4f7f\u6761\u4ef6\u8bed\u53e5\u548c\u5faa\u73af\u8bed\u53e5\u53d8\u5f97\u66f4\u52a0\u7075\u6d3b\u3002<\/h2>\n
\u201c\u987a\u5e8f\u7ed3\u6784\u201d\u4ee3\u8868\u201c\u5148\u6267\u884ca\uff0c\u518d\u6267\u884cb\u201d\u7684\u903b\u8f91\u3002
\u201c\u6761\u4ef6\u5224\u65ad\u7ed3\u6784\u201d\u4ee3\u8868\u201c\u5982\u679c\u2026\uff0c\u5219\u2026\u201d\u7684\u903b\u8f91\u3002
\u201c\u5faa\u73af\u7ed3\u6784\u201d\u4ee3\u8868\u201c\u5982\u679c\u2026\uff0c\u5219\u91cd\u590d\u6267\u884c\u2026\u201d\u7684\u903b\u8f91\u3002<\/span><\/p>\n<\/p>\n
<\/p>\n","protected":false},"excerpt":{"rendered":"\u7b2c\u4e09\u7ae0 \u6d41\u7a0b\u63a7\u5236_\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u56fe3.1\u7a0b\u5e8f\u7ed3\u67843.2\u6761\u4ef6\u8bed\u53e53.2.1if\u6761\u4ef6\u8bed\u53e5\u4f8b3.2\u4e24\u79cd\u60c5\u51b5\u90fd\u662f\u6b63\u786e\u7684\u200b\u4f8b3.2\u62e8\u6253\u7535\u8bdd3.if...elseif...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8120"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8120"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8120\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}