{"id":327,"date":"2020-11-02T18:05:12","date_gmt":"2020-11-02T22:05:12","guid":{"rendered":"http:\/\/www.prglab.com\/blog\/?page_id=327"},"modified":"2020-11-02T18:05:12","modified_gmt":"2020-11-02T22:05:12","slug":"control-structures","status":"publish","type":"page","link":"https:\/\/www.prglab.com\/blog\/cplusplus-tutorial\/program-structure\/control-structures","title":{"rendered":"\u63a7\u5236\u7ed3\u6784"},"content":{"rendered":"\n<h2>2.1 \u63a7\u5236\u7ed3\u6784\uff08Control Structures\uff09<\/h2>\n\n\n\n<p>\u4e00\u4e2a\u7a0b\u5e8f\u7684\u8bed\u53e5\u5f80\u5f80\u5e76\u4e0d\u4ec5\u9650\u4e8e\u7ebf\u6027\u987a\u5e8f\u7ed3\u6784\u3002\u5728\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u4e2d\u5b83\u53ef\u80fd\u88ab\u5206\u6210\u4e24\u652f\u6267\u884c\uff0c\u53ef\u80fd\u91cd\u590d\u67d0\u4e9b\u8bed\u53e5\uff0c\u4e5f\u53ef\u80fd\u6839\u636e\u4e00\u4e9b\u5224\u65ad\u7ed3\u679c\u800c\u6267\u884c\u4e0d\u540c\u7684\u8bed\u53e5\u3002\u56e0\u6b64C++ \u63d0\u4f9b\u4e00\u4e9b\u63a7\u5236\u7ed3\u6784\u8bed\u53e5 (control structures) \u6765\u5b9e\u73b0\u8fd9\u4e9b\u6267\u884c\u987a\u5e8f\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u4ecb\u7ecd\u7a0b\u5e8f\u7684\u6267\u884c\u987a\u5e8f\uff0c\u6211\u4eec\u9700\u8981\u5148\u4ecb\u7ecd\u4e00\u4e2a\u65b0\u6982\u5ff5\uff1a\u8bed\u53e5\u5757(block of instructions)\u3002\u4e00\u4e2a\u8bed\u53e5\u5757(A block of instructions) \u662f\u4e00\u7ec4\u4e92\u76f8\u4e4b\u95f4\u7531\u5206\u53f7semicolons (;) \u5206\u9694\u5f00\u4f46\u6574\u4f53\u88ab\u82b1\u62ec\u53f7curly bracket signs: { and }\u62ec\u8d77\u6765\u7684\u8bed\u53e5\u3002<\/p>\n\n\n\n<p>\u672c\u8282\u4e2d\u6211\u4eec\u5c06\u770b\u5230\u7684\u5927\u591a\u6570\u63a7\u5236\u7ed3\u6784\u5141\u8bb8\u4e00\u4e2a\u901a\u7528\u7684statement\u505a\u53c2\u6570\uff0c\u8fd9\u4e2astatement\u6839\u636e\u9700\u8981\u53ef\u4ee5\u662f\u4e00\u6761\u8bed\u53e5\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u7ec4\u8bed\u53e5\u7ec4\u6210\u7684\u8bed\u53e5\u5757\u3002\u5982\u679c\u6211\u4eec\u53ea\u9700\u8981\u4e00\u6761\u8bed\u53e5\u505astatement\uff0c\u5b83\u53ef\u4ee5\u4e0d\u88ab\u62ec\u5728\u82b1\u62ec\u53f7 ({}) \u5185\u3002\u4f46\u5982\u679c\u6211\u4eec\u9700\u8981\u591a\u6761\u8bed\u53e5\u5171\u540c\u505astatement\uff0c\u5219\u5fc5\u987b\u628a\u5b83\u4eec\u62ec\u5728\u82b1\u62ec\u53f7\u5185 ({}) \u4ee5\u7ec4\u6210\u4e00\u4e2a\u8bed\u53e5\u5757\u3002<\/p>\n\n\n\n<h3>\u6761\u4ef6\u7ed3\u6784Conditional structure: if and else<\/h3>\n\n\n\n<p>\u6761\u4ef6\u7ed3\u6784\u7528\u6765\u5b9e\u73b0\u4ec5\u5728\u67d0\u79cd\u6761\u4ef6\u6ee1\u8db3\u7684\u60c5\u51b5\u4e0b\u624d\u6267\u884c\u4e00\u6761\u8bed\u53e5\u6216\u4e00\u4e2a\u8bed\u53e5\u5757\u3002\u5b83\u7684\u5f62\u5f0f\u662f\uff1a<code>if (condition) statement<\/code><\/p>\n\n\n\n<p>\u8fd9\u91cc condition \u662f\u4e00\u4e2a\u5c06\u88ab\u8ba1\u7b97\u7684\u8868\u8fbe\u5f0f\uff08expression\uff09\u3002\u5982\u679c\u8868\u8fbe\u5f0f\u503c\u4e3a\u771f\uff0c\u5373\u6761\u4ef6(condition)\u4e3atrue\uff0cstatement \u5c06\u88ab\u6267\u884c\u3002\u5426\u5219\uff0cstatement \u5c06\u88ab\u5ffd\u7565\uff08\u4e0d\u88ab\u6267\u884c\uff09\uff0c\u7a0b\u5e8f\u4ece\u6574\u4e2a\u6761\u4ef6\u7ed3\u6784\u4e4b\u540e\u7684\u4e0b\u4e00\u6761\u8bed\u53e5\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u7a0b\u5e8f\u6bb5\u5b9e\u73b0\u53ea\u6709\u5f53\u53d8\u91cfx\u5b58\u50a8\u7684\u503c\u786e\u5b9e\u4e3a100\u7684\u65f6\u5019\u624d\u8f93\u51fa&#8221;x is 100&#8243;\uff1aif (x == 100)<br>cout &lt;&lt; &#8220;x is 100&#8221;;<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u9700\u8981\u5728\u6761\u4ef6condition\u4e3a\u771ftrue\u7684\u65f6\u5019\u6267\u884c\u4e00\u6761\u4ee5\u4e0a\u7684\u8bed\u53e5\uff0c\u6211\u4eec\u53ef\u4ee5\u82b1\u62ec\u53f7{}\u5c06\u8bed\u53e5\u62ec\u8d77\u6765\u7ec4\u6210\u4e00\u4e2a\u8bed\u53e5\u5757\uff1aif (x == 100)<br>{<br>cout &lt;&lt; &#8220;x is &#8220;;<br>cout &lt;&lt; x;<br>}<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u7528\u5173\u952e\u5b57else \u6765\u6307\u5b9a\u5f53\u6761\u4ef6\u4e0d\u80fd\u88ab\u6ee1\u8db3\u65f6\u9700\u8981\u6267\u884c\u7684\u8bed\u53e5\uff0c\u5b83\u9700\u8981\u548cif \u4e00\u8d77\u4f7f\u7528\uff0c\u5f62\u5f0f\u662f\uff1a<code>if (condition) statement1 else statement2<\/code><\/p>\n\n\n\n<p>\u4f8b\u5982\uff1aif (x == 100)<br>cout &lt;&lt; &#8220;x is 100&#8221;;<br>else<br>cout &lt;&lt; &#8220;x is not 100&#8221;;<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u5982\u679cx\u7684\u503c\u4e3a100\uff0c\u5219\u5728\u5c4f\u5e55\u4e0a\u6253\u51fax is 100\uff0c\u5982\u679cx\u4e0d\u662f100\uff0c\u800c\u4e14\u4e5f\u53ea\u6709\u5728x\u4e0d\u662f100\u7684\u65f6\u5019\uff0c\u5c4f\u5e55\u4e0a\u5c06\u6253\u51fax is not 100\u3002<\/p>\n\n\n\n<p>\u591a\u4e2aif + else \u7684\u7ed3\u6784\u88ab\u8fde\u63a5\u8d77\u6765\u4f7f\u7528\u6765\u5224\u65ad\u6570\u503c\u7684\u8303\u56f4\u3002\u4ee5\u4e0b\u4f8b\u5b50\u663e\u793a\u4e86\u5982\u4f55\u7528\u5b83\u6765\u5224\u65ad\u53d8\u91cf x\u4e2d\u5f53\u524d\u5b58\u50a8\u7684\u6570\u503c\u662f\u6b63\u503c\uff0c\u8d1f\u503c\u8fd8\u662f\u65e2\u4e0d\u6b63\u4e5f\u4e0d\u8d1f\uff0c\u5373\u7b49\u4e8e0 \u3002if (x &gt; 0)<br>cout &lt;&lt; &#8220;x is positive&#8221;;<br>else if (x &lt; 0)<br>cout &lt;&lt; &#8220;x is negative&#8221;;<br>else<br>cout &lt;&lt; &#8220;x is 0&#8221;;<\/p>\n\n\n\n<p>\u8bb0\u4f4f\u5f53\u6211\u4eec\u9700\u8981\u6267\u884c\u591a\u6761\u8bed\u53e5\u65f6\uff0c\u5fc5\u987b\u4f7f\u7528\u82b1\u62ec\u53f7{}\u5c06\u5b83\u4eec\u62ec\u8d77\u6765\u4ee5\u7ec4\u6210\u4e00\u4e2a\u8bed\u53e5\u5757block of instructions\u3002<\/p>\n\n\n\n<h3>\u91cd\u590d\u7ed3\u6784 Iteration structures \u6216\u5faa\u73afloops<\/h3>\n\n\n\n<p>\u5faa\u73afLoops \u7684\u76ee\u7684\u662f\u91cd\u590d\u6267\u884c\u4e00\u7ec4\u8bed\u53e5\u4e00\u5b9a\u7684\u6b21\u6570\u6216\u76f4\u5230\u6ee1\u8db3\u67d0\u79cd\u6761\u4ef6\u3002<\/p>\n\n\n\n<h4>while \u5faa\u73af<\/h4>\n\n\n\n<p>\u683c\u5f0f\u662f\uff1a<code>while (\u8868\u8fbe\u5f0fexpression) \u8bed\u53e5statement<\/code><\/p>\n\n\n\n<p>\u5b83\u7684\u529f\u80fd\u662f\u5f53expression \u7684\u503c\u4e3a\u771ftrue\u65f6\u91cd\u590d\u6267\u884cstatement\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u7528while\u5faa\u73af\u6765\u5199\u4e00\u4e2a\u5012\u8ba1\u6570\u7a0b\u5e8f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ custom countdown using while<br>#include &lt;iostream.h&gt;<br>int main ()<br>{<br>int n;<br>cout &lt;&lt; &#8220;Enter the starting number &gt; &#8220;;<br>cin &gt;&gt; n;<br>while (n&gt;0) {<br>cout &lt;&lt; n &lt;&lt; &#8220;, &#8220;;<br>&#8211;n;<br>}<br>cout &lt;&lt; &#8220;FIRE!&#8221;;<br>return 0;<br>}<\/td><td>Enter the starting number &gt; 8<br>8, 7, 6, 5, 4, 3, 2, 1, FIRE!<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u7a0b\u5e8f\u5f00\u59cb\u65f6\u63d0\u793a\u7528\u6237\u8f93\u5165\u4e00\u4e2a\u5012\u8ba1\u6570\u7684\u521d\u59cb\u503c\u3002\u7136\u540ewhile \u5faa\u73af\u5f00\u59cb\uff0c\u5982\u679c\u7528\u6237\u8f93\u5165\u7684\u6570\u503c\u6ee1\u8db3\u6761\u4ef6n&gt;0 (\u5373 n \u6bd40 \u5927)\uff0c\u540e\u9762\u8ddf\u7684\u8bed\u53e5\u5757\u5c06\u4f1a\u88ab\u6267\u884c\u4e00\u5b9a\u7684\u6b21\u6570\uff0c\u76f4\u5230\u6761\u4ef6 (n&gt;0) \u4e0d\u518d\u6ee1\u8db3\uff08\u53d8\u4e3afalse\uff09\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u7684\u6240\u6709\u5904\u7406\u8fc7\u7a0b\u53ef\u4ee5\u7528\u4ee5\u4e0b\u7684\u63cf\u8ff0\u6765\u89e3\u91ca\uff1a<\/p>\n\n\n\n<p>\u4ece<strong>main<\/strong>\u5f00\u59cb\uff1a<\/p>\n\n\n\n<ol><li>\u7528\u6237\u8f93\u5165\u4e00\u4e2a\u6570\u503c\u8d4b\u7ed9n.<\/li><li>while\u8bed\u53e5\u68c0\u67e5(n&gt;0)\u662f\u5426\u6210\u7acb\uff0c\u8fd9\u65f6\u6709\u4e24\u79cd\u53ef\u80fd\uff1a<ul><li>true: \u6267\u884cstatement (\u5230\u7b2c3\u6b65)<\/li><li>false: \u8df3\u8fc7statement. \u7a0b\u5e8f\u76f4\u63a5\u6267\u884c\u7b2c5\u6b65.<\/li><\/ul><\/li><li>\u6267\u884cstatement:<br><code>cout &lt;&lt; n &lt;&lt; \", \";<br>--n;<\/code>(\u5c06n \u7684\u503c\u6253\u5370\u5728\u5c4f\u5e55\u4e0a\uff0c\u7136\u540e\u5c06n \u7684\u503c\u51cf1).<\/li><li>\u8bed\u53e5\u5757\u7ed3\u675f\uff0c\u81ea\u52a8\u8fd4\u56de\u7b2c2\u6b65\u3002<\/li><li>\u7ee7\u7eed\u6267\u884c\u8bed\u53e5\u5757\u4e4b\u540e\u7684\u7a0b\u5e8f\uff1a\u6253\u5370 FIRE! \uff0c\u7a0b\u5e8f\u7ed3\u675f\u3002<\/li><\/ol>\n\n\n\n<p>\u6211\u4eec\u5fc5\u987b\u8003\u8651\u5230\u5faa\u73af\u5fc5\u987b\u5728\u67d0\u4e2a\u70b9\u7ed3\u675f\uff0c\u56e0\u6b64\u5728\u8bed\u53e5\u5757\u4e4b\u5185\uff08loop\u7684statement\u4e4b\u5185) \u6211\u4eec\u5fc5\u987b\u63d0\u4f9b\u4e00\u4e9b\u65b9\u6cd5\u4f7f\u5f97\u6761\u4ef6condition \u53ef\u4ee5\u5728\u67d0\u4e2a\u65f6\u523b\u53d8\u4e3a\u5047 false\uff0c\u5426\u5219\u5faa\u73af\u5c06\u65e0\u9650\u91cd\u590d\u4e0b\u53bb\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u91cc\uff0c\u6211\u4eec\u7528\u8bed\u53e5&#8211;n;\u4f7f\u5f97\u5faa\u73af\u5728\u91cd\u590d\u4e00\u5b9a\u7684\u6b21\u6570\u540e\u53d8\u4e3afalse \uff1a\u5f53 n \u53d8\u4e3a0\uff0c \u5012\u8ba1\u6570\u7ed3\u675f\u3002<\/p>\n\n\n\n<h4>do-while \u5faa\u73af<\/h4>\n\n\n\n<p>\u683c\u5f0f\uff1a<code>do \u8bed\u53e5statement while (\u6761\u4ef6condition);<\/code><\/p>\n\n\n\n<p>\u5b83\u7684\u529f\u80fd\u4e0ewhile \u5faa\u73af\u4e00\u62b9\u4e00\u6837\uff0c\u9664\u4e86\u5728do-while\u5faa\u73af\u4e2d\u662f\u5148\u6267\u884cstatement \u7136\u540e\u624d\u68c0\u67e5\u6761\u4ef6condition \uff0c\u800c\u4e0d\u60f3while\u5faa\u73af\u4e2d\u5148\u68c0\u67e5\u6761\u4ef6\u7136\u540e\u624d\u6267\u884cstatement\u3002\u8fd9\u6837\uff0c\u5373\u4f7f\u6761\u4ef6condition\u4ece\u6765\u6ca1\u6709\u88ab\u6ee1\u8db3\u8fc7\uff0cstatement \u4ecd\u81f3\u5c11\u88ab\u6267\u884c\u4e00\u6b21\u3002\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u7a0b\u5e8f\u91cd\u590d\u8f93\u51fa\uff08echoes\uff09\u7528\u6237\u8f93\u5165\u7684\u4efb\u4f55\u6570\u503c\uff0c\u76f4\u5230\u7528\u6237\u8f93\u51650\u4e3a\u6b62\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ number echoer<br>#include &lt;iostream.h&gt;<br>int main ()<br>{<br>unsigned long n;<br>do {<br>cout &lt;&lt; &#8220;Enter number (0 to end): &#8220;;<br>cin &gt;&gt; n;<br>cout &lt;&lt; &#8220;You entered: &#8221; &lt;&lt; n &lt;&lt; &#8220;\\n&#8221;;<br>} while (n != 0);<br>return 0;<br>}<\/td><td>Enter number (0 to end): 12345<br>You entered: 12345<br>Enter number (0 to end): 160277<br>You entered: 160277<br>Enter number (0 to end): 0<br>You entered: 0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><em>do-while<\/em>&nbsp;\u5faa\u73af\u901a\u5e38\u88ab\u7528\u5728\u5224\u65ad\u5faa\u73af\u7ed3\u675f\u7684\u6761\u4ef6\u662f\u5728\u5faa\u73af\u8bed\u53e5\u5185\u90e8\u88ab\u51b3\u5b9a\u7684\u60c5\u51b5\u4e0b\uff0c\u6bd4\u5982\u4ee5\u4e0a\u7684\u4f8b\u5b50\uff0c\u5728\u5faa\u73af\u7684\u8bed\u53e5\u5757\u5185\u7528\u6237\u7684\u8f93\u5165\u51b3\u5b9a\u4e86\u5faa\u73af\u662f\u5426\u7ed3\u675f\u3002\u5982\u679c\u7528\u6237\u6c38\u8fdc\u4e0d\u8f93\u51650\uff0c\u5219\u5faa\u73af\u6c38\u8fdc\u4e0d\u4f1a\u7ed3\u675f\u3002<\/p>\n\n\n\n<h4>for \u5faa\u73af<\/h4>\n\n\n\n<p>\u683c\u5f0f\u662f\uff1a<code>for (initialization; condition; increase) statement;<\/code><\/p>\n\n\n\n<p>\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u662f\u5f53\u6761\u4ef6condition \u4e3a\u771f<strong>true<\/strong>\u65f6\u91cd\u590d\u6267\u884c\u8bed\u53e5statement \uff0c\u7c7b\u4f3cwhile \u5faa\u73af\u3002\u4f46\u9664\u6b64\u4e4b\u5916\uff0cfor \u8fd8\u63d0\u4f9b\u4e86\u5199\u521d\u59cb\u5316\u8bed\u53e5initialization \u548c\u589e\u503c\u8bed\u53e5increase \u7684\u5730\u65b9\u3002\u56e0\u6b64\u8fd9\u79cd\u5faa\u73af\u7ed3\u6784\u662f\u7279\u522b\u4e3a\u6267\u884c\u7531\u8ba1\u6570\u5668\u63a7\u5236\u7684\u5faa\u73af\u800c\u8bbe\u8ba1\u7684\u3002<\/p>\n\n\n\n<p>\u5b83\u6309\u4ee5\u4e0b\u65b9\u5f0f\u5de5\u4f5c\uff1a<\/p>\n\n\n\n<ol><li>\u6267\u884c\u521d\u59cb\u5316initialization \u3002\u901a\u5e38\u5b83\u662f\u8bbe\u7f6e\u4e00\u4e2a\u8ba1\u6570\u5668\u53d8\u91cf\uff08counter variable\uff09\u7684\u521d\u59cb\u503c\uff0c\u521d\u59cb\u5316\u4ec5\u88ab\u6267\u884c\u4e00\u6b21\u3002<\/li><li>\u68c0\u67e5\u6761\u4ef6condition \uff0c\u5982\u679c\u6761\u4ef6\u4e3a\u771ftrue\uff0c\u7ee7\u7eed\u5faa\u73af\uff0c\u5426\u5219\u5faa\u73af\u7ed3\u675f\u5faa\u73af\u4e2d\u8bed\u53e5statement \u88ab\u8df3\u8fc7\u3002<\/li><li>\u6267\u884c\u8bed\u53e5statement \u3002\u50cf\u4ee5\u524d\u4e00\u6837\uff0c\u5b83\u53ef\u4ee5\u662f\u4e00\u4e2a\u5355\u72ec\u7684\u8bed\u53e5\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u7531\u82b1\u62ec\u53f7{ }\u62ec\u8d77\u6765\u7684\u8bed\u53e5\u5757\u3002<\/li><li>\u6700\u540e\u589e\u503c\u57df\uff08increase field\uff09\u4e2d\u7684\u8bed\u53e5\u88ab\u6267\u884c\uff0c\u5faa\u73af\u8fd4\u56de\u7b2c2\u6b65\u3002\u6ce8\u610f\u589e\u503c\u57df\u4e2d\u53ef\u80fd\u662f\u4efb\u4f55\u8bed\u53e5\uff0c\u800c\u4e0d\u4e00\u5b9a\u53ea\u662f\u5c06\u8ba1\u6570\u5668\u589e\u52a0\u7684\u8bed\u53e5\u3002\u4f8b\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\u8ba1\u6570\u5668\u5b9e\u9645\u4e3a\u51cf1\uff0c\u800c\u4e0d\u662f\u52a01\u3002<\/li><\/ol>\n\n\n\n<p>\u4e0b\u9762\u662f\u7528for\u5faa\u73af\u5b9e\u73b0\u7684\u5012\u8ba1\u6570\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ countdown using a for loop<br>#include &lt;iostream.h&gt;<br>int main ()<br>{<br>for (int n=10; n&gt;0; n&#8211;) {<br>cout &lt;&lt; n &lt;&lt; &#8220;, &#8220;;<br>}<br>cout &lt;&lt; &#8220;FIRE!&#8221;;<br>return 0;<br>}<\/td><td>10, 9, 8, 7, 6, 5, 4, 3, 2, 1, FIRE!<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u521d\u59cb\u5316initialization \u548c\u589e\u503cincrease \u57df\u662f\u53ef\u9009\u7684\uff08\u5373\u53ef\u4ee5\u4e3a\u7a7a\uff09\u3002\u4f46\u8fd9\u4e9b\u57df\u4e3a\u7a7a\u7684\u65f6\u5019\uff0c\u5b83\u4eec\u548c\u5176\u4ed6\u57df\u4e4b\u95f4\u95f4\u9694\u7684\u5206\u53f7\u4e0d\u53ef\u4ee5\u7701\u7565\u3002\u4f8b\u5982\u6211\u4eec\u53ef\u4ee5\u5199\uff1afor (;n&lt;10;)\u6765\u8868\u793a\u6ca1\u6709\u521d\u59cb\u5316\u548c\u589e\u503c\u8bed\u53e5\uff1b\u6216for (;n&lt;10;n++) \u6765\u8868\u793a\u6709\u589e\u503c\u8bed\u53e5\u4f46\u6ca1\u6709\u521d\u59cb\u5316\u8bed\u53e5\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u6211\u4eec\u4e5f\u53ef\u4ee5\u5728for\u5faa\u73af\u521d\u59cb\u5316\u6216\u589e\u503c\u57df\u4e2d\u653e\u4e00\u6761\u4ee5\u4e0a\u7684\u8bed\u53e5\uff0c\u4e2d\u95f4\u7528\u9017\u53f7 coma(,)\u9694\u5f00\u3002\u4f8b\u5982\u5047\u8bbe\u6211\u4eec\u60f3\u5728\u5faa\u73af\u4e2d\u521d\u59cb\u5316\u4e00\u4e2a\u4ee5\u4e0a\u7684\u53d8\u91cf\uff0c\u53ef\u4ee5\u7528\u4ee5\u4e0b\u7684\u7a0b\u5e8f\u6765\u5b9e\u73b0\uff1afor ( n=0, i=100 ; n!=i ; n++, i&#8211; )<br>{<br>\/\/ whatever here&#8230;<br>}<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u5faa\u73af\u5c06\u88ab\u6267\u884c50 \u6b21\uff0c\u5982\u679cn \u548ci \u5728\u5faa\u8fd8\u5185\u90e8\u90fd\u4e0d\u88ab\u6539\u53d8\u7684\u8bdd\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/www.prglab.com\/cms\/media\/images\/cplusplus\/img2-1-1.gif\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>n<\/strong>\u521d\u59cb\u503c\u4e3a<strong>0<\/strong>\uff0c<strong>i<\/strong>\u521d\u59cb\u503c\u4e3a<strong>100<\/strong>\uff0c\u6761\u4ef6\u662f<strong>(n!=i)<\/strong>(\u5373<strong>n<\/strong>\u4e0d\u80fd\u7b49\u4e8e<strong>i<\/strong>)\u3002\u56e0\u4e3a\u6bcf\u6b21\u5faa\u73af<strong>n<\/strong>\u52a0<strong>1<\/strong>\uff0c\u800c\u4e14<strong>i<\/strong>\u51cf<strong>1<\/strong>\uff0c\u5faa\u73af\u7684\u6761\u4ef6\u5c06\u4f1a\u5728\u7b2c50\u6b21\u5faa\u73af\u4e4b\u540e\u53d8\u4e3a\u5047<strong>false<\/strong>\uff08<strong>n<\/strong>&nbsp;\u548c&nbsp;<strong>i<\/strong>&nbsp;\u90fd\u7b49\u4e8e<strong>50<\/strong>\uff09\u3002<\/p>\n\n\n\n<h3>\u5206\u652f\u63a7\u5236\u548c\u8df3\u8f6c(Bifurcation of control and jumps)<\/h3>\n\n\n\n<h4>break \u8bed\u53e5<\/h4>\n\n\n\n<p>\u901a\u8fc7\u4f7f\u7528<strong>break<\/strong>\u8bed\u53e5\uff0c\u5373\u4f7f\u5728\u7ed3\u675f\u6761\u4ef6\u6ca1\u6709\u6ee1\u8db3\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u8df3\u51fa\u4e00\u4e2a\u5faa\u73af\u3002\u5b83\u53ef\u4ee5\u88ab\u7528\u6765\u7ed3\u675f\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\uff08infinite loop\uff09\uff0c\u6216\u5f3a\u8feb\u5faa\u73af\u5728\u5176\u81ea\u7136\u7ed3\u675f\u4e4b\u524d\u7ed3\u675f\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u60f3\u8981\u5728\u5012\u8ba1\u6570\u81ea\u7136\u7ed3\u675f\u4e4b\u524d\u5f3a\u8feb\u5b83\u505c\u6b62\uff08\u4e5f\u8bb8\u56e0\u4e3a\u4e00\u4e2a\u5f15\u64ce\u6545\u969c\uff09\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ break loop example<br>#include &lt;iostream.h&gt;<br>int main ()<br>{<br>int n;<br>for (n=10; n&gt;0; n&#8211;) {<br>cout &lt;&lt; n &lt;&lt; &#8220;, &#8220;;<br>if (n==3)<br>{<br>cout &lt;&lt; &#8220;countdown aborted!&#8221;;<br>break;<br>}<br>return 0;<br>}<\/td><td>10, 9, 8, 7, 6, 5, 4, 3, countdown aborted!<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4>continue \u8bed\u53e5<\/h4>\n\n\n\n<p><strong>continue<\/strong>\u8bed\u53e5\u4f7f\u5f97\u7a0b\u5e8f\u8df3\u8fc7\u5f53\u524d\u5faa\u73af\u4e2d\u5269\u4e0b\u7684\u90e8\u5206\u800c\u76f4\u63a5\u8fdb\u5165\u4e0b\u4e00\u6b21\u5faa\u73af\uff0c\u5c31\u597d\u50cf\u5faa\u73af\u4e2d\u8bed\u53e5\u5757\u7684\u7ed3\u5c3e\u5df2\u7ecf\u5230\u4e86\u4f7f\u5f97\u5faa\u73af\u8fdb\u5165\u4e0b\u4e00\u6b21\u91cd\u590d\u3002\u4f8b\u5982\uff0c\u4e0b\u9762\u4f8b\u5b50\u4e2d\u5012\u8ba1\u6570\u65f6\u6211\u4eec\u5c06\u8df3\u8fc7\u6570\u5b575\u7684\u8f93\u51fa\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ continue loop example<br>#include &lt;iostream.h&gt;<br>int main ()<br>{<br>for (int n=10; n&gt;0; n&#8211;) {<br>if (n==5) continue;<br>cout &lt;&lt; n &lt;&lt; &#8220;, &#8220;;<br>}<br>cout &lt;&lt; &#8220;FIRE!&#8221;;<br>return 0;<br>}<\/td><td>10, 9, 8, 7, 6, 4, 3, 2, 1, FIRE!<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4>goto \u8bed\u53e5<\/h4>\n\n\n\n<p>\u901a\u8fc7\u4f7f\u7528goto\u8bed\u53e5\u53ef\u4ee5\u4f7f\u7a0b\u5e8f\u4ece\u4e00\u70b9\u8df3\u8f6c\u5230\u53e6\u5916\u4e00\u70b9\u3002\u4f60\u5fc5\u987b\u8c28\u614e\u53ea\u7528\u8fd9\u6761\u8bed\u53e5\uff0c\u56e0\u4e3a\u5b83\u7684\u6267\u884c\u53ef\u4ee5\u5ffd\u7565\u4efb\u4f55\u5d4c\u5957\u9650\u5236\u3002<\/p>\n\n\n\n<p>\u8df3\u8f6c\u7684\u76ee\u6807\u70b9\u53ef\u4ee5\u7531\u4e00\u4e2a\u6807\u793a\u7b26(label)\u6765\u6807\u660e\uff0c\u8be5\u6807\u793a\u7b26\u4f5c\u4e3agoto\u8bed\u53e5\u7684\u53c2\u6570\u3002\u4e00\u4e2a\u6807\u793a\u7b26(label)\u7531\u4e00\u4e2a\u6807\u8bc6\u540d\u79f0\u540e\u9762\u8ddf\u4e00\u4e2a\u5192\u53f7colon (:)\u7ec4\u6210\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\u9664\u4e86\u5e95\u5c42\u7a0b\u5e8f\u7231\u597d\u8005\u4f7f\u7528\u8fd9\u6761\u8bed\u53e5\uff0c\u5b83\u5728\u7ed3\u6784\u5316\u6216\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u4e2d\u5e76\u4e0d\u5e38\u7528\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\u6211\u4eec\u7528goto\u6765\u5b9e\u73b0\u5012\u8ba1\u6570\u5faa\u73af\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ goto loop example<br>#include &lt;iostream.h&gt;<br>int main ()<br>{<br>int n=10;<br>loop:<br>cout &lt;&lt; n &lt;&lt; &#8220;, &#8220;;<br>n&#8211;;<br>if (n&gt;0) goto loop;<br>cout &lt;&lt; &#8220;FIRE!&#8221;;<br>return 0;<br>}<\/td><td>10, 9, 8, 7, 6, 5, 4, 3, 2, 1, FIRE!<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4>exit \u51fd\u6570<\/h4>\n\n\n\n<p><strong>exit<\/strong>\u662f\u4e00\u4e2a\u5728<a href=\"http:\/\/www.cplusplus.com\/ref\/cstdlib\" target=\"_blank\" rel=\"noreferrer noopener\">cstdlib (stdlib.h)<\/a>\u5e93\u4e2d\u5b9a\u4e49\u7684\u51fd\u6570\u3002<\/p>\n\n\n\n<p><strong>exit<\/strong>\u7684\u76ee\u7684\u662f\u4e00\u4e2a\u7279\u5b9a\u7684\u9000\u51fa\u4ee3\u7801\u6765\u7ed3\u675f\u7a0b\u5e8f\u7684\u8fd0\u884c\uff0c\u5b83\u7684\u539f\u578b(prototype)\u662f\uff1a<code>void exit (int exit code);<\/code><\/p>\n\n\n\n<p><strong>exit code<\/strong>\u662f\u7531\u64cd\u4f5c\u7cfb\u7edf\u4f7f\u7528\u6216\u88ab\u8c03\u7528\u7a0b\u5e8f\u4f7f\u7528\u3002\u901a\u5e38<strong>exit code<\/strong>\u4e3a<strong>0<\/strong>\u8868\u793a\u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f\uff0c\u4efb\u4f55\u5176\u4ed6\u503c\u8868\u793a\u7a0b\u5e8f\u6267\u884c\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u4e86\u9519\u8bef\u3002<\/p>\n\n\n\n<h3>\u9009\u62e9\u7ed3\u6784The selective Structure: switch<\/h3>\n\n\n\n<p><strong>switch<\/strong>&nbsp;\u8bed\u53e5\u7684\u8bed\u6cd5\u6bd4\u8f83\u7279\u6b8a\u3002\u5b83\u7684\u76ee\u6807\u662f\u5bf9\u4e00\u4e2a\u8868\u8fbe\u5f0f\u68c0\u67e5\u591a\u4e2a\u53ef\u80fd\u5e38\u91cf\u503c\uff0c\u6709\u4e9b\u50cf\u6211\u4eec\u5728\u672c\u8282\u5f00\u5934\u5b66\u4e60\u7684\u628a\u51e0\u4e2aif \u548celse if \u8bed\u53e5\u8fde\u63a5\u8d77\u6765\u7684\u7ed3\u6784\u3002\u5b83\u7684\u5f62\u5f0f\u662f\uff1aswitch (expression) {<br>case constant1:<br>block of instructions 1<br>break;<br>case constant2:<br>block of instructions 2<br>break;<br>.<br>.<br>.<br>default:<br>default block of instructions<br>}<\/p>\n\n\n\n<p>\u5b83\u6309\u4ee5\u4e0b\u65b9\u5f0f\u6267\u884c\uff1a<\/p>\n\n\n\n<p>switch \u8ba1\u7b97\u8868\u8fbe\u5f0fexpression \u7684\u503c\uff0c\u5e76\u68c0\u67e5\u5b83\u662f\u5426\u4e0e\u7b2c\u4e00\u4e2a\u5e38\u91cfconstant1\u76f8\u7b49\uff0c\u5982\u679c\u76f8\u7b49\uff0c\u7a0b\u5e8f\u6267\u884c\u5e38\u91cf1\u540e\u9762\u7684\u8bed\u53e5\u5757block of instructions 1 \u76f4\u5230\u78b0\u5230\u5173\u952e\u5b57break \uff0c\u7a0b\u5e8f\u8df3\u8f6c\u5230switch \u9009\u62e9\u7ed3\u6784\u7684\u7ed3\u5c3e\u5904\u3002<\/p>\n\n\n\n<p>\u5982\u679cexpression \u4e0d\u7b49\u4e8econstant1\uff0c\u7a0b\u5e8f\u68c0\u67e5\u8868\u8fbe\u5f0fexpression \u7684\u503c\u662f\u5426\u7b49\u4e8e\u7b2c\u4e8c\u4e2a\u5e38\u91cfconstant2\uff0c \u5982\u679c\u76f8\u7b49\uff0c\u7a0b\u5e8f\u5c06\u6267\u884c\u5e38\u91cf2\u540e\u9762\u7684\u8bed\u53e5\u5757block of instructions 2 \u76f4\u5230\u78b0\u5230\u5173\u952e\u5b57break\u3002<\/p>\n\n\n\n<p>\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u6700\u540e\u5982\u679c\u8868\u8fbe\u5f0fexpression \u7684\u503c\u4e0d\u7b49\u4e8e\u4efb\u4f55\u524d\u9762\u7684\u5e38\u91cf\uff08\u4f60\u53ef\u4ee5\u7528case\u8bed\u53e5\u6307\u660e\u4efb\u610f\u6570\u91cf\u7684\u5e38\u91cf\u503c\u6765\u8981\u6c42\u68c0\u67e5\uff09\uff0c\u7a0b\u5e8f\u5c06\u6267\u884c\u9ed8\u8ba4\u533adefault: \u540e\u9762\u7684\u8bed\u53e5\uff0c\u5982\u679c\u5b83\u5b58\u5728\u7684\u8bdd\u3002default: \u9009\u9879\u662f\u53ef\u4ee5\u7701\u7565\u7684\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u7684\u4e24\u6bb5\u4ee3\u7801\u6bb5\u529f\u80fd\u76f8\u540c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th><em>switch<\/em>&nbsp;example<\/th><th><em>if-else<\/em>&nbsp;equivalent<\/th><\/tr><tr><td>switch (x) {<br>case 1:<br>cout &lt;&lt; &#8220;x is 1&#8221;;<br>break;<br>case 2:<br>cout &lt;&lt; &#8220;x is 2&#8221;;<br>break;<br>default:<br>cout &lt;&lt; &#8220;value of x unknown&#8221;;<br>}<\/td><td>if (x == 1) {<br>cout &lt;&lt; &#8220;x is 1&#8221;;<br>}<br>else if (x == 2) {<br>cout &lt;&lt; &#8220;x is 2&#8221;;<br>}<br>else {<br>cout &lt;&lt; &#8220;value of x unknown&#8221;;<br>}<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u524d\u9762\u5df2\u7ecf\u63d0\u5230<strong>switch<\/strong>\u7684\u8bed\u6cd5\u6709\u70b9\u7279\u6b8a\u3002\u6ce8\u610f\u6bcf\u4e2a\u8bed\u53e5\u5757\u7ed3\u5c3e\u5305\u542b\u7684<strong>break<\/strong>\u8bed\u53e5\u3002\u8fd9\u662f\u5fc5\u987b\u7684\uff0c\u56e0\u4e3a\u5982\u679c\u4e0d\u8fd9\u6837\u505a\uff0c\u4f8b\u5982\u5728\u8bed\u53e5\u5757block of instructions 1 \u7684\u7ed3\u5c3e\u6ca1\u6709<strong>break<\/strong>\uff0c\u7a0b\u5e8f\u6267\u884c\u5c06\u4e0d\u4f1a\u8df3\u8f6c\u5230<strong>switch<\/strong>\u9009\u62e9\u7684\u7ed3\u5c3e\u5904 (<strong>}<\/strong>) \uff0c\u800c\u662f\u7ee7\u7eed\u6267\u884c\u4e0b\u9762\u7684\u8bed\u53e5\u5757\uff0c\u76f4\u5230\u7b2c\u4e00\u6b21\u9047\u5230<strong>break<\/strong>\u8bed\u53e5\u6216\u5230<strong>switch<\/strong>\u9009\u62e9\u7ed3\u6784\u7684\u7ed3\u5c3e\u3002\u56e0\u6b64\uff0c\u4e0d\u9700\u8981\u5728\u6bcf\u4e00\u4e2acase \u57df\u5185\u52a0\u82b1\u62ec\u53f7<strong>{ }<\/strong>&nbsp;\u3002\u8fd9\u4e2a\u7279\u70b9\u540c\u65f6\u53ef\u4ee5\u5e2e\u52a9\u5b9e\u73b0\u5bf9\u4e0d\u540c\u7684\u53ef\u80fd\u503c\u6267\u884c\u76f8\u540c\u7684\u8bed\u53e5\u5757\u3002\u4f8b\u5982\uff1aswitch (x) {<br>case 1:<br>case 2:<br>case 3:<br>cout &lt;&lt; &#8220;x is 1, 2 or 3&#8221;;<br>break;<br>default:<br>cout &lt;&lt; &#8220;x is not 1, 2 nor 3&#8221;;<br>}<\/p>\n\n\n\n<p><strong>\u6ce8\u610f<\/strong><strong>switch<\/strong>\u53ea\u80fd\u88ab\u7528\u6765\u6bd4\u8f83\u8868\u8fbe\u5f0f\u548c\u4e0d\u540c\u5e38\u91cf\u7684\u503cconstants\u3002\u56e0\u6b64\u6211\u4eec\u4e0d\u80fd\u591f\u628a\u53d8\u91cf\u6216\u8303\u56f4\u653e\u5728case\u4e4b\u540e\uff0c\u4f8b\u5982 (case (n*2):) \u6216 (case (1..3):) \u90fd\u4e0d\u53ef\u4ee5\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u662f\u6709\u6548\u7684\u5e38\u91cf\u3002 \u5982\u679c\u4f60\u9700\u8981\u68c0\u67e5\u8303\u56f4\u6216\u975e\u5e38\u91cf\u6570\u503c\uff0c\u4f7f\u7528\u8fde\u7eed\u7684if \u548celse if \u8bed\u53e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2.1 \u63a7\u5236\u7ed3\u6784\uff08Control Structures\uff09 \u4e00\u4e2a\u7a0b\u5e8f\u7684\u8bed\u53e5\u5f80\u5f80\u5e76\u4e0d\u4ec5\u9650\u4e8e\u7ebf\u6027\u987a\u5e8f\u7ed3\u6784\u3002\u5728\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u4e2d\u5b83\u53ef\u80fd\u88ab\u5206\u6210\u4e24\u652f\u6267\u884c\uff0c\u53ef\u80fd\u91cd\u590d\u67d0\u4e9b\u8bed\u53e5\uff0c\u4e5f\u53ef\u80fd\u6839\u636e\u4e00\u4e9b\u5224\u65ad\u7ed3\u679c\u800c\u6267\u884c\u4e0d\u540c\u7684\u8bed\u53e5\u3002\u56e0\u6b64C++ \u63d0\u4f9b\u4e00\u4e9b\u63a7\u5236\u7ed3\u6784\u8bed\u53e5 (control structures) \u6765\u5b9e\u73b0\u8fd9\u4e9b\u6267\u884c\u987a\u5e8f\u3002 \u4e3a\u4e86\u4ecb\u7ecd\u7a0b\u5e8f\u7684\u6267\u884c\u987a\u5e8f\uff0c\u6211\u4eec\u9700\u8981\u5148\u4ecb\u7ecd\u4e00\u4e2a\u65b0\u6982\u5ff5\uff1a\u8bed\u53e5\u5757(block of instructions)\u3002\u4e00\u4e2a\u8bed\u53e5\u5757(A block of instructions) \u662f\u4e00\u7ec4\u4e92\u76f8\u4e4b\u95f4\u7531\u5206\u53f7semicolons (;) \u5206\u9694\u5f00\u4f46\u6574\u4f53\u88ab\u82b1\u62ec\u53f7curly bracket signs: { and }\u62ec\u8d77\u6765\u7684\u8bed\u53e5\u3002 \u672c\u8282\u4e2d\u6211\u4eec\u5c06\u770b\u5230\u7684\u5927\u591a\u6570\u63a7\u5236\u7ed3\u6784\u5141\u8bb8\u4e00\u4e2a\u901a\u7528\u7684statement\u505a\u53c2\u6570\uff0c\u8fd9\u4e2astatement\u6839\u636e\u9700\u8981\u53ef\u4ee5\u662f\u4e00\u6761\u8bed\u53e5\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u7ec4\u8bed\u53e5\u7ec4\u6210\u7684\u8bed\u53e5\u5757\u3002\u5982\u679c\u6211\u4eec\u53ea\u9700\u8981\u4e00\u6761\u8bed\u53e5\u505astatement\uff0c\u5b83\u53ef\u4ee5\u4e0d\u88ab\u62ec\u5728\u82b1\u62ec\u53f7 ({}) \u5185\u3002\u4f46\u5982\u679c\u6211\u4eec\u9700\u8981\u591a\u6761\u8bed\u53e5\u5171\u540c\u505astatement\uff0c\u5219\u5fc5\u987b\u628a\u5b83\u4eec\u62ec\u5728\u82b1\u62ec\u53f7\u5185 ({}) \u4ee5\u7ec4\u6210\u4e00\u4e2a\u8bed\u53e5\u5757\u3002 \u6761\u4ef6\u7ed3\u6784Conditional structure: if and else \u6761\u4ef6\u7ed3\u6784\u7528\u6765\u5b9e\u73b0\u4ec5\u5728\u67d0\u79cd\u6761\u4ef6\u6ee1\u8db3\u7684\u60c5\u51b5\u4e0b\u624d\u6267\u884c\u4e00\u6761\u8bed\u53e5\u6216\u4e00\u4e2a\u8bed\u53e5\u5757\u3002\u5b83\u7684\u5f62\u5f0f\u662f\uff1aif (condition) statement \u8fd9\u91cc condition \u662f\u4e00\u4e2a\u5c06\u88ab\u8ba1\u7b97\u7684\u8868\u8fbe\u5f0f\uff08expression\uff09\u3002\u5982\u679c\u8868\u8fbe\u5f0f\u503c\u4e3a\u771f\uff0c\u5373\u6761\u4ef6(condition)\u4e3atrue\uff0cstatement \u5c06\u88ab\u6267\u884c\u3002\u5426\u5219\uff0cstatement \u5c06\u88ab\u5ffd\u7565\uff08\u4e0d\u88ab\u6267\u884c\uff09\uff0c\u7a0b\u5e8f\u4ece\u6574\u4e2a\u6761\u4ef6\u7ed3\u6784\u4e4b\u540e\u7684\u4e0b\u4e00\u6761\u8bed\u53e5\u7ee7\u7eed\u6267\u884c\u3002 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u7a0b\u5e8f\u6bb5\u5b9e\u73b0\u53ea\u6709\u5f53\u53d8\u91cfx\u5b58\u50a8\u7684\u503c\u786e\u5b9e\u4e3a100\u7684\u65f6\u5019\u624d\u8f93\u51fa&#8221;x is 100&#8243;\uff1aif (x == 100)cout &lt;&lt; &#8220;x is 100&#8221;; \u5982\u679c\u6211\u4eec\u9700\u8981\u5728\u6761\u4ef6condition\u4e3a\u771ftrue\u7684\u65f6\u5019\u6267\u884c\u4e00\u6761\u4ee5\u4e0a\u7684\u8bed\u53e5\uff0c\u6211\u4eec\u53ef\u4ee5\u82b1\u62ec\u53f7{}\u5c06\u8bed\u53e5\u62ec\u8d77\u6765\u7ec4\u6210\u4e00\u4e2a\u8bed\u53e5\u5757\uff1aif (x == 100){cout &lt;&lt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":325,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/327"}],"collection":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/comments?post=327"}],"version-history":[{"count":1,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/327\/revisions"}],"predecessor-version":[{"id":328,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/327\/revisions\/328"}],"up":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/325"}],"wp:attachment":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/media?parent=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}