{"id":71,"date":"2015-09-20T16:37:29","date_gmt":"2015-09-20T08:37:29","guid":{"rendered":"http:\/\/501a.xiaobaidonghui.cn\/wordpress\/?p=71"},"modified":"2016-09-19T22:28:25","modified_gmt":"2016-09-19T14:28:25","slug":"71","status":"publish","type":"post","link":"http:\/\/www.taoteam.tech\/?p=71","title":{"rendered":"JAVA\u4e2d\u7684\u5faa\u73af\u7ed3\u6784"},"content":{"rendered":"<h1>\u5faa\u73af\u8bed\u53e5<\/h1>\n<p>\u5faa\u73af\u8bed\u53e5\u4e3b\u8981\u5206\u4e3a<code>for<\/code>\u5faa\u73af\u548c<code>while<\/code>\u5faa\u73af\u4e24\u79cd\u3002for\u5faa\u73af\u4e00\u822c\u7528\u5728\u9884\u5148\u5df2\u7ecf\u77e5\u9053\u5faa\u73af\u6b21\u6570\u7684\u60c5\u5f62\uff08\u5982\u8981\u8ba1\u7b971+2+&#8230;+100\u7684\u7ed3\u679c\uff09\uff0c\u800c\u5982\u679c\u4e0d\u80fd\u786e\u5b9a\u5faa\u73af\u6b21\u6570\u5c31\u9700\u8981\u4f7f\u7528while\u5faa\u73af\uff08\u5982\u590d\u5236\u4e00\u4e2a\u6587\u4ef6\uff0c\u4f46\u4e0d\u77e5\u9053\u6587\u4ef6\u7684\u5177\u4f53\u5927\u5c0f\uff09\u3002<\/p>\n<h1>\u7b80\u6613for\u5faa\u73af<\/h1>\n<pre class=\\\"lang:java mark:1 decode:true \\\">for(\u53c2\u6570\u521d\u59cb\u5316\u8868\u8fbe\u5f0f; \u6761\u4ef6\u8868\u8fbe\u5f0f; \u66f4\u65b0\u5faa\u73af\u53d8\u91cf\u8868\u8fbe\u5f0f)\n{\n    \/\/do something\n}<\/pre>\n<ol>\n<li>for\u5faa\u73af\u7684\u62ec\u53f7\u4e2d\uff0c\u7528\u4e24\u4e2a\u5206\u53f7\u5206\u9694\u51fa\u4e09\u4e2a\u8868\u8fbe\u5f0f<\/li>\n<li>\u8fd9\u4e09\u4e2a\u8868\u8fbe\u5f0f\u90fd\u662f\u53ef\u9009\u7684\uff0c\u5373\u662f\u53ef\u4ee5\u7701\u7565\u7684\u3002<\/li>\n<li>\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e09\u4e2a\u8868\u8fbe\u5f0f\u53ef\u4ee5\u662f\u9017\u53f7\u8868\u8fbe\u5f0f\u3002<\/li>\n<\/ol>\n<pre class=\\\"lang:java mark:1 decode:true \\\">for (int i = 0, j = 0; i &lt; 2; ++i, j = j + 2)\n{\n    \/\/do something\n}<\/pre>\n<h1>continue \u548c break<\/h1>\n<p>continue\u7684\u4f5c\u7528\u662f\u7ed3\u675f\u672c\u6b21\u5faa\u73af\u3002\u5373\u8df3\u51fa\u5faa\u73af\u4f53\u4e2d\u4e0b\u9762\u5c1a\u672a\u6267\u884c\u7684\u8bed\u53e5\u3002<br \/>\n &#8211; \u5bf9\u4e8ewhile\u5faa\u73af\uff0c\u7ee7\u7eed\u5224\u65ad\u5faa\u73af\u6761\u4ef6\u662f\u5426\u6210\u7acb\u3002<br \/>\n &#8211; \u5bf9\u4e8efor\u5faa\u73af\uff0c\u6267\u884cfor\u8bed\u53e5\u5934\u4e2d\u7b2c\u4e09\u4e2a\u8868\u8fbe\u5f0f\uff0c\u7136\u540e\u5224\u65ad\u5faa\u73af\u6761\u4ef6\u662f\u5426\u6210\u7acb\u3002<\/p>\n<p>break\u8bed\u53e5\u7684\u5219\u662f\u7ed3\u675f\u6574\u4e2a\u5faa\u73af\u8fc7\u7a0b\uff0c\u4e0d\u518d\u5224\u65ad\u6267\u884c\u5faa\u73af\u7684\u6761\u4ef6\u662f\u5426\u6210\u7acb\u3002<\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u7684\u4f5c\u7528\u5bf9\u8c61\u662f\u672c\u5c42\u5faa\u73af\uff0c\u5728\u591a\u5c42\u5faa\u73af\u4e2d, break\u8bed\u53e5\u53ea\u5411\u5916\u8df3\u4e00\u5c42\uff0ccontinue\u8bed\u53e5\u4e5f\u53ea\u662f\u63d0\u524d\u7ed3\u675f\u672c\u5c42\u672c\u6b21\u5faa\u73af\u3002<\/p>\n<h1>\u591a\u5c42\u5d4c\u5957\u5faa\u73af\u4e2d\u7684break<\/h1>\n<pre class=\\\"lang:java decode:true \\\">package cn.xiaobaidonghui.test;\n\/**\n * \u8fd9\u662f\u5173\u4e8e\u5faa\u73af\u91cc\u7684break\u7528\u6cd5\n * \u901a\u5e38\u60c5\u51b5\u4e0bbreak\u7528\u4e8e\u8df3\u51fa\u5f53\u524d\u5c42\u5faa\u73af\u3002\u5f53\u9047\u5230\u5d4c\u5957\u5faa\u73af\u65f6\uff0c\u600e\u4e48\u6837\u80fd\u8df3\u51fa\u5916\u5c42\u5faa\u73af\u5462\u3002\n * \n * @author baidonghui\n *\/\npublic class testBreak\n{\n    public static void main(String[] args)\n    {\n        System.out.println(\\\"for1\\\");\n        for1();\n        System.out.println(\\\"for2\\\");\n        for2();\n        System.out.println(\\\"for3\\\");\n        for3();\n    }\n    \n    \/**\n     * \u8fd9\u662f\u4e00\u4e2a\u4e09\u5c42\u5faa\u73af\uff0c\u6bcf\u5c42\u5faa\u73af\u53d8\u91cf\u4e3a\u6574\u6570[0,3)\uff0c\u5728\u6700\u5185\u4fa7\u5faa\u73af\u4e2d\u5f53k\u53d6\u503c\u4e3a1\u65f6\uff0c\u8df3\u51fa\u6700\u5185\u5c42\u5faa\u73af\u3002\n     *\/\n    public static void for1()\n    {\n        for(int i = 0; i &lt; 3; i++)\n        {\n            for(int j = 0; j&lt; 3;j++)\n            {\n                for(int k = 0; k &lt;3; k ++)\n                {\n                    System.out.println(i +\\\" \\\" + j + \\\" \\\" + k);\n                    if(k==1)\n                    {\n                        break;\n                    }\n                }\n            }\n        } \n    }\n    \n    \/**\n     * \u672c\u51fd\u6570\u4e0e {@link #for1()}\u7684\u533a\u522b\u662f\uff1a\u4e3a\u4e2d\u95f4\u5c42\u5faa\u73af\u52a0\u4e86\u6807\u53f7\uff0c\u5f53\u6700\u5185\u5c42k=1\u65f6\u6267\u884cbreak LABEL_FOR\uff0c\u8df3\u51fa\u4e2d\u95f4\u5c42\u5faa\u73af\u3002\n     *\/\n    public static void for2()\n    {\n        for(int i = 0; i &lt; 3; i++)\n        {\n            LABEL_FOR:\n            for(int j = 0; j&lt; 3;j++)\n            {\n                for(int k = 0; k &lt;3; k ++)\n                {\n                    System.out.println(i +\\\" \\\" + j + \\\" \\\" + k);\n                    if(k==1)\n                    {\n                        break LABEL_FOR; \n                    }\n                }\n            }\n        } \n    }\n    \n    \/**\n     * \u672c\u51fd\u6570\u4e0e {@link #for1()}\u7684\u533a\u522b\u662f\uff1a\u4e3a\u6700\u5916\u5c42\u5faa\u73af\u52a0\u4e86\u6807\u53f7\uff0c\u5f53\u6700\u5185\u5c42k=1\u65f6\u6267\u884cbreak LABEL_FOR\uff0c\u8df3\u51fa\u6700\u5916\u5c42\u5faa\u73af\uff0c\u51fd\u6570\u9000\u51fa\u3002\n     *\/\n    public static void for3()\n    {\n        LABEL_FOR:\n        for(int i = 0; i &lt; 3; i++)\n        {\n            for(int j = 0; j&lt; 3;j++)\n            {\n                for(int k = 0; k &lt;3; k ++)\n                {\n                    System.out.println(i +\\\" \\\" + j + \\\" \\\" + k);\n                    if(k==1)\n                    {\n                        break LABEL_FOR; \n                    }\n                }\n            }\n        } \n    }\n}\n<\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre class=\\\"lang:default highlight:0 decode:true \\\">for1\n0 0 0\n0 0 1\n0 1 0\n0 1 1\n0 2 0\n0 2 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1\n1 2 0\n1 2 1\n2 0 0\n2 0 1\n2 1 0\n2 1 1\n2 2 0\n2 2 1\nfor2\n0 0 0\n0 0 1\n1 0 0\n1 0 1\n2 0 0\n2 0 1\nfor3\n0 0 0\n0 0 1\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5faa\u73af\u8bed\u53e5 \u5faa\u73af\u8bed\u53e5\u4e3b\u8981\u5206\u4e3afor\u5faa\u73af\u548cwhile\u5faa\u73af\u4e24\u79cd\u3002for\u5faa\u73af\u4e00\u822c\u7528\u5728\u9884\u5148\u5df2\u7ecf\u77e5\u9053\u5faa\u73af\u6b21\u6570\u7684\u60c5\u5f62\uff08\u5982\u8981\u8ba1 [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=\/wp\/v2\/posts\/71"}],"collection":[{"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=71"}],"version-history":[{"count":5,"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":76,"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=\/wp\/v2\/posts\/71\/revisions\/76"}],"wp:attachment":[{"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.taoteam.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}