{"id":74575,"date":"2024-02-27T11:57:23","date_gmt":"2024-02-27T03:57:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=74575"},"modified":"2024-02-27T11:57:39","modified_gmt":"2024-02-27T03:57:39","slug":"c%e8%af%ad%e8%a8%80%e4%b8%ad%e7%9a%84%e5%be%aa%e7%8e%af%e6%8e%a7%e5%88%b6%e7%bb%93%e6%9e%84%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/74575.html","title":{"rendered":"C\u8bed\u8a00\u4e2d\u7684\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u6709\u54ea\u4e9b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-74576\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/02\/img-OYVaGfOqdmV0bZ5YAIF2lqHD.png?x-oss-process=image\/auto-orient,1\/format,webp\" width=\"600\" height=\"342\" alt=\"C\u8bed\u8a00\u4e2d\u7684\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u6709\u54ea\u4e9b\" \/><\/p>\n<p>### C\u8bed\u8a00\u4e2d\u7684\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u6709\u54ea\u4e9b<\/p>\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u662f\u5b9e\u73b0\u4ee3\u7801\u91cd\u590d\u6267\u884c\u7684\u57fa\u7840\u3002<strong>C\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e09\u79cd\u4e3b\u8981\u7684\u5faa\u73af\u63a7\u5236\u7ed3\u6784\uff1a`for`\u5faa\u73af\u3001`while`\u5faa\u73af\u3001\u548c`do-while`\u5faa\u73af<\/strong>\u3002\u8fd9\u4e9b\u7ed3\u6784\u4f7f\u5f97\u7a0b\u5e8f\u80fd\u591f\u6839\u636e\u6761\u4ef6\u53cd\u590d\u6267\u884c\u67d0\u6bb5\u4ee3\u7801\uff0c\u662f\u7f16\u7a0b\u4e2d\u5b9e\u73b0\u8fed\u4ee3\u7684\u5173\u952e\u3002\u5176\u4e2d\uff0c<strong>`for`\u5faa\u73af<\/strong>\u56e0\u5176\u7ed3\u6784\u6e05\u6670\u3001\u6613\u4e8e\u7406\u89e3\u548c\u63a7\u5236\uff0c\u5e38\u88ab\u7528\u4e8e\u6267\u884c\u5df2\u77e5\u6b21\u6570\u7684\u5faa\u73af\u3002<\/p>\n<p>`for`\u5faa\u73af\u7684\u57fa\u672c\u5f62\u5f0f\u5305\u62ec\u521d\u59cb\u5316\u8868\u8fbe\u5f0f\u3001\u5faa\u73af\u6761\u4ef6\u548c\u8fed\u4ee3\u8868\u8fbe\u5f0f\u3002\u5b83\u9996\u5148\u6267\u884c\u521d\u59cb\u5316\u6b65\u9aa4\uff0c\u7136\u540e\u5728\u6bcf\u6b21\u8fed\u4ee3\u5f00\u59cb\u524d\u8bc4\u4f30\u5faa\u73af\u6761\u4ef6\uff0c\u5e76\u5728\u6bcf\u6b21\u8fed\u4ee3\u5b8c\u6210\u540e\u6267\u884c\u8fed\u4ee3\u8868\u8fbe\u5f0f\u3002\u8fd9\u79cd\u5faa\u73af\u7279\u522b\u9002\u5408\u4e8e\u5faa\u73af\u6b21\u6570\u5df2\u77e5\u7684\u60c5\u51b5\u3002<\/p>\n<p>### \u4e00\u3001FOR\u5faa\u73af<\/p>\n<p>For\u5faa\u73af\u662f\u6700\u5e38\u89c1\u7684\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u4e4b\u4e00\uff0c\u5b83\u7279\u522b\u9002\u5408\u4e8e\u5f53\u6211\u4eec\u4e8b\u5148\u77e5\u9053\u5faa\u73af\u6b21\u6570\u65f6\u4f7f\u7528\u3002<\/p>\n<p>&#8211; <strong>\u57fa\u672c\u8bed\u6cd5<\/strong>\uff1afor\u5faa\u73af\u7684\u8bed\u6cd5\u5305\u62ec\u4e09\u4e2a\u90e8\u5206\uff1a\u521d\u59cb\u5316\u3001\u6761\u4ef6\u5224\u65ad\u3001\u8fed\u4ee3\u6b65\u9aa4\u3002\u5b83\u7684\u6267\u884c\u6d41\u7a0b\u662f\u9996\u5148\u6267\u884c\u521d\u59cb\u5316\u64cd\u4f5c\uff0c\u7136\u540e\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\uff0c\u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u5219\u6267\u884c\u5faa\u73af\u4f53\u5185\u7684\u8bed\u53e5\uff0c\u6700\u540e\u6267\u884c\u8fed\u4ee3\u6b65\u9aa4\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u4e00\u76f4\u91cd\u590d\uff0c\u76f4\u5230\u6761\u4ef6\u5224\u65ad\u4e3a\u5047\u3002<\/p>\n<p>&#8211; <strong>\u5e94\u7528\u573a\u666f<\/strong>\uff1afor\u5faa\u73af\u975e\u5e38\u9002\u7528\u4e8e\u5faa\u73af\u6b21\u6570\u5df2\u77e5\u7684\u60c5\u51b5\uff0c\u6bd4\u5982\u904d\u5386\u6570\u7ec4\u5143\u7d20\u3001\u91cd\u590d\u6267\u884c\u67d0\u64cd\u4f5c\u56fa\u5b9a\u6b21\u6570\u7b49\u573a\u666f\u3002<\/p>\n<p>### \u4e8c\u3001WHILE\u5faa\u73af<\/p>\n<p>While\u5faa\u73af\u662f\u4e00\u79cd\u57fa\u4e8e\u6761\u4ef6\u7684\u5faa\u73af\u63a7\u5236\u7ed3\u6784\uff0c\u5b83\u4f1a\u5728\u6bcf\u6b21\u5faa\u73af\u5f00\u59cb\u524d\u68c0\u67e5\u6761\u4ef6\uff0c\u53ea\u8981\u6761\u4ef6\u4e3a\u771f\uff0c\u5faa\u73af\u5c31\u4f1a\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<p>&#8211; <strong>\u57fa\u672c\u8bed\u6cd5<\/strong>\uff1awhile\u5faa\u73af\u7684\u8bed\u6cd5\u53ea\u5305\u542b\u4e00\u4e2a\u6761\u4ef6\u8868\u8fbe\u5f0f\u3002\u5728\u5faa\u73af\u4f53\u6267\u884c\u524d\uff0c\u9996\u5148\u8bc4\u4f30\u8fd9\u4e2a\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u5982\u679c\u7ed3\u679c\u4e3a\u771f\uff0c\u5219\u6267\u884c\u5faa\u73af\u4f53\u5185\u7684\u8bed\u53e5\uff0c\u5faa\u73af\u4f53\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u518d\u6b21\u68c0\u67e5\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u4e00\u76f4\u91cd\u590d\u3002<\/p>\n<p>&#8211; <strong>\u5e94\u7528\u573a\u666f<\/strong>\uff1awhile\u5faa\u73af\u9002\u5408\u4e8e\u90a3\u4e9b\u6211\u4eec\u4e8b\u5148\u4e0d\u77e5\u9053\u5177\u4f53\u5faa\u73af\u6b21\u6570\uff0c\u4f46\u80fd\u591f\u901a\u8fc7\u6761\u4ef6\u5224\u65ad\u63a7\u5236\u5faa\u73af\u7ee7\u7eed\u6216\u7ed3\u675f\u7684\u60c5\u51b5\u3002<\/p>\n<p>### \u4e09\u3001DO-WHILE\u5faa\u73af<\/p>\n<p>Do-while\u5faa\u73af\u662f\u4e00\u79cd\u540e\u6d4b\u8bd5\u5faa\u73af\u63a7\u5236\u7ed3\u6784\uff0c\u5b83\u4fdd\u8bc1\u4e86\u5faa\u73af\u4f53\u5185\u7684\u8bed\u53e5\u81f3\u5c11\u6267\u884c\u4e00\u6b21\u3002<\/p>\n<p>&#8211; <strong>\u57fa\u672c\u8bed\u6cd5<\/strong>\uff1a\u4e0ewhile\u5faa\u73af\u76f8\u6bd4\uff0cdo-while\u5faa\u73af\u9996\u5148\u6267\u884c\u4e00\u6b21\u5faa\u73af\u4f53\u5185\u7684\u8bed\u53e5\uff0c\u7136\u540e\u518d\u5bf9\u6761\u4ef6\u8868\u8fbe\u5f0f\u8fdb\u884c\u8bc4\u4f30\u3002\u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u5219\u7ee7\u7eed\u6267\u884c\u5faa\u73af\u4f53\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u4e00\u76f4\u91cd\u590d\u3002<\/p>\n<p>&#8211; <strong>\u5e94\u7528\u573a\u666f<\/strong>\uff1ado-while\u5faa\u73af\u7279\u522b\u9002\u7528\u4e8e\u90a3\u4e9b\u81f3\u5c11\u9700\u8981\u6267\u884c\u4e00\u6b21\u5faa\u73af\u4f53\uff0c\u4e4b\u540e\u518d\u6839\u636e\u6761\u4ef6\u5224\u65ad\u662f\u5426\u7ee7\u7eed\u6267\u884c\u7684\u573a\u666f\u3002<\/p>\n<p>### \u56db\u3001\u5faa\u73af\u63a7\u5236\u8bed\u53e5<\/p>\n<p>\u5728\u4f7f\u7528\u5faa\u73af\u65f6\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u63d0\u524d\u7ec8\u6b62\u5faa\u73af\u6216\u8df3\u8fc7\u67d0\u4e9b\u8fed\u4ee3\u3002C\u8bed\u8a00\u63d0\u4f9b\u4e86\u51e0\u79cd\u5faa\u73af\u63a7\u5236\u8bed\u53e5\u6765\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\uff0c\u5305\u62ec`break`\u548c`continue`\u3002<\/p>\n<p>&#8211; <strong>BREAK<\/strong>\uff1a`break`\u8bed\u53e5\u53ef\u4ee5\u7528\u4e8e\u4efb\u4f55\u7c7b\u578b\u7684\u5faa\u73af\u4e2d\uff0c\u5305\u62ec`for`\u3001`while`\u548c`do-while`\u5faa\u73af\u3002\u5b83\u7528\u4e8e\u7acb\u5373\u9000\u51fa\u5faa\u73af\uff0c\u65e0\u8bba\u5faa\u73af\u6761\u4ef6\u662f\u5426\u4ecd\u7136\u4e3a\u771f\u3002<\/p>\n<p>&#8211; <strong>CONTINUE<\/strong>\uff1a`continue`\u8bed\u53e5\u4e5f\u53ef\u4ee5\u7528\u5728\u6240\u6709\u7c7b\u578b\u7684\u5faa\u73af\u4e2d\u3002\u5b83\u7528\u4e8e\u8df3\u8fc7\u5f53\u524d\u5faa\u73af\u7684\u5269\u4f59\u90e8\u5206\uff0c\u76f4\u63a5\u8fdb\u5165\u4e0b\u4e00\u6b21\u5faa\u73af\u7684\u6761\u4ef6\u5224\u65ad\u3002<\/p>\n<p>\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u8fd9\u4e9b\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u548c\u8bed\u53e5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u7075\u6d3b\u6027\u548c\u6548\u7387\uff0c\u89e3\u51b3\u5404\u79cd\u9700\u8981\u91cd\u590d\u6267\u884c\u4ee3\u7801\u7684\u95ee\u9898\u3002<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u6709\u54ea\u4e9b\u5e38\u89c1\u7684C\u8bed\u8a00\u5faa\u73af\u7ed3\u6784\uff1f<\/strong><\/p>\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u5e38\u89c1\u7684\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u6709for\u5faa\u73af\u3001while\u5faa\u73af\u548cdo-while\u5faa\u73af\u3002for\u5faa\u73af\u901a\u8fc7\u521d\u59cb\u5316\u3001\u6761\u4ef6\u5224\u65ad\u548c\u66f4\u65b0\u4e09\u90e8\u5206\u6765\u63a7\u5236\u5faa\u73af\u6b21\u6570\uff1bwhile\u5faa\u73af\u5728\u6bcf\u6b21\u5faa\u73af\u4e4b\u524d\u5224\u65ad\u6761\u4ef6\u662f\u5426\u4e3a\u771f\uff0c\u5982\u679c\u4e3a\u771f\u5c31\u6267\u884c\u5faa\u73af\u4f53\uff1bdo-while\u5faa\u73af\u4e0d\u8bba\u6761\u4ef6\u662f\u5426\u4e3a\u771f\u90fd\u4f1a\u5148\u6267\u884c\u4e00\u6b21\u5faa\u73af\u4f53\uff0c\u518d\u5224\u65ad\u662f\u5426\u7ee7\u7eed\u5faa\u73af\u3002<\/p>\n<p><strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5faa\u73af\u7ed3\u6784\u6765\u89e3\u51b3\u95ee\u9898\uff1f<\/strong><\/p>\n<p>\u5728\u9009\u62e9\u5faa\u73af\u7ed3\u6784\u65f6\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u95ee\u9898\u60c5\u51b5\u6765\u51b3\u5b9a\u3002\u5982\u679c\u5faa\u73af\u6b21\u6570\u662f\u786e\u5b9a\u7684\uff0c\u63a8\u8350\u4f7f\u7528for\u5faa\u73af\uff1b\u5982\u679c\u5faa\u73af\u6b21\u6570\u4e0d\u786e\u5b9a\u4e14\u81f3\u5c11\u4f1a\u6267\u884c\u4e00\u6b21\u5faa\u73af\u4f53\uff0c\u53ef\u9009\u62e9do-while\u5faa\u73af\uff1b\u5982\u679c\u5faa\u73af\u6b21\u6570\u4e0d\u786e\u5b9a\u4e14\u53ef\u80fd\u4e00\u6b21\u90fd\u4e0d\u6267\u884c\u5faa\u73af\u4f53\uff0c\u53ef\u9009\u62e9while\u5faa\u73af\u3002<\/p>\n<p><strong>\u5faa\u73af\u7ed3\u6784\u5728C\u8bed\u8a00\u7f16\u7a0b\u4e2d\u6709\u4f55\u4f5c\u7528\uff1f<\/strong><\/p>\n<p>\u5faa\u73af\u7ed3\u6784\u5728C\u8bed\u8a00\u7f16\u7a0b\u4e2d\u975e\u5e38\u91cd\u8981\uff0c\u53ef\u4ee5\u91cd\u590d\u6267\u884c\u4e00\u6bb5\u4ee3\u7801\u5757\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u590d\u7528\u6027\u548c\u6548\u7387\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u5faa\u73af\u7ed3\u6784\uff0c\u53ef\u4ee5\u907f\u514d\u4ee3\u7801\u91cd\u590d\u3001\u7b80\u5316\u7a0b\u5e8f\u7ed3\u6784\u3001\u51cf\u5c11\u4ee3\u7801\u91cf\uff0c\u5e76\u80fd\u6709\u6548\u5904\u7406\u5faa\u73af\u4efb\u52a1\uff0c\u5b9e\u73b0\u591a\u6b21\u6267\u884c\u540c\u4e00\u6bb5\u4ee3\u7801\u7684\u76ee\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"### C\u8bed\u8a00\u4e2d\u7684\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u6709\u54ea\u4e9b \u5728C\u8bed\u8a00\u4e2d\uff0c\u5faa\u73af\u63a7\u5236\u7ed3\u6784\u662f\u5b9e\u73b0\u4ee3\u7801\u91cd\u590d\u6267\u884c\u7684\u57fa\u7840\u3002C\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e09\u79cd\u4e3b\u8981\u7684 [&hellip;]","protected":false},"author":1,"featured_media":74578,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/74575"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=74575"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/74575\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/74578"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=74575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=74575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=74575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}