{"id":457,"date":"2015-07-05T19:32:45","date_gmt":"2015-07-05T11:32:45","guid":{"rendered":"http:\/\/yangwang.hk\/?p=457"},"modified":"2015-12-06T17:21:32","modified_gmt":"2015-12-06T09:21:32","slug":"3-3%e3%80%81while%e5%be%aa%e7%8e%af","status":"publish","type":"post","link":"https:\/\/yangwang.hk\/?p=457","title":{"rendered":"3.3\u3001while\u5faa\u73af"},"content":{"rendered":"<p>\u8ba1\u7b97\u673a\u5f88\u64c5\u957f\u4e8e\u5e72\u91cd\u590d\u7684\u4e8b\u60c5\uff0c\u56e0\u4e3a\u4ed6\u6ca1\u6709\u60c5\u611f\uff0c\u5e76\u4e0d\u4f1a\u56e0\u4e3a\u91cd\u590d\u800c\u611f\u5230\u538c\u70e6\u3002<\/p>\n<p>\u53ef\u4ee5\u8bf4\u7edd\u5927\u591a\u6570\u7a0b\u5e8f\u90fd\u4f1a\u7528\u5230\u5faa\u73af\uff01\u800c\u73b0\u5728\u6211\u4eec\u5c31\u5c06\u5b66\u4e60\u4e00\u79cd\u5faa\u73af\u8bed\u53e5\u2014\u2014while\u8bed\u53e5<\/p>\n<p>\u548c\u4e0a\u4e00\u7bc7\u6587\u7ae0\u7c7b\u4f3c\uff0c\u6211\u4eec\u5c06\u5c1d\u8bd5\u7740\u4f7f\u7528\u65b0\u5b66\u7684\u77e5\u8bc6\u6765\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f<\/p>\n<p>\u6211\u4eec\u5c06\u7f16\u5199\u4e00\u4e2a\u80fd\u6253\u5370\u6444\u6c0f\u5ea6\u4e0e\u534e\u6c0f\u5ea6\u6362\u7b97\u8868\u7684\u7a0b\u5e8f\u3002\u4ee510\u4e3a\u6b65\u957f\uff0c\u8f93\u51fa\u4ece0-100\u6444\u6c0f\u5ea6\u7684\u5bf9\u5e94\u7684\u534e\u6c0f\u5ea6\u7684\u7a0b\u5e8f<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\nint main()\r\n{\r\n    printf(&quot;\u6444\u6c0f\u5ea6\\t\u534e\u6c0f\u5ea6:\\n&quot;);\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u9996\u5148\u662f\u7a0b\u5e8f\u7684\u57fa\u672c\u6846\u67b6\uff0c\u56e0\u4e3a\u6211\u4eec\u5e0c\u671b\u8ba9\u8ba1\u7b97\u673a\u5e2e\u6211\u4eec\u7b97\u51fa\u4ed6\u4eec\u7684\u5bf9\u5e94\u5173\u7cfb\uff0c\u800c\u4e0d\u662f\u6211\u4eec\u624b\u5de5\u53bb\u8ba1\u7b97\uff0c\u56e0\u6b64\u5c31\u6d89\u53ca\u5230\u5faa\u73af\u7684\u77e5\u8bc6<\/p>\n<p>C\u8bed\u8a00\u5f53\u4e2d\u6709\u4e09\u79cd\u4e13\u95e8\u7684\u5faa\u73af\u8bed\u53e5\uff0c\u5206\u522b\u662fwhile\uff0cdo&#8230;while\uff0c\u548cfor<\/p>\n<p>\u5176\u4e2dwhile\u7684\u7528\u6cd5\u76f8\u5bf9\u4e8e\u5176\u4ed6\u51e0\u79cd\u5faa\u73af\u6765\u8bf4\u7a0d\u5fae\u7b80\u5355\u4e00\u4e9b\uff0c\u56e0\u6b64\u6211\u4eec\u4fbf\u4ecewhile\u5f00\u59cb\u5b66\u4e60\u5faa\u73af<\/p>\n<p>while\u7684\u7ed3\u6784\u6709\u4e9b\u7c7b\u4f3cif<\/p>\n<p><strong><em>while (&#8230;)<\/em><\/strong><br \/>\n<strong><em>{<\/em><\/strong><br \/>\n<strong><em>\/\/\u5faa\u73af\u7684\u4ee3\u7801<\/em><\/strong><br \/>\n<strong><em>}<\/em><\/strong><\/p>\n<p>\u548cif\u7c7b\u4f3c\uff0cwhile\u7684\u540e\u9762\u5e76\u6ca1\u6709\u5206\u53f7\uff0c\u540c\u65f6\u5c0f\u62ec\u53f7\u5185\u7684&#8230;\u53eb\u505a<strong>\u6761\u4ef6\u8868\u8fbe\u5f0f<\/strong><\/p>\n<p>\u800c\u5927\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u90e8\u5206\u5219\u53eb\u505a\u5faa\u73af\u4f53<\/p>\n<p>\u6267\u884c\u5230while\u65f6\uff0c\u5f53\u5c0f\u62ec\u53f7\u5185\u7684\u8868\u8fbe\u5f0f\u7684\u503c\u4e3a\u771f\u65f6\uff0c\u5c06\u4f1a\u4ece\u5faa\u73af\u4f53\u7684\u7b2c\u4e00\u884c\uff0c\u6309\u7167\u76f8\u5e94\u7684\u903b\u8f91\u6267\u884c<\/p>\n<p>\u5728\u5faa\u73af\u4f53\u6267\u884c\u5b8c\u4e00\u6b21\u540e\uff0c\u5c06\u518d\u6b21\u5224\u65ad\u5c0f\u62ec\u53f7\u5185\u7684\u8868\u8fbe\u5f0f\u662f\u5426\u4e3a\u771f\uff0c\u5982\u679c\u662f\u771f\uff0c\u5219\u91cd\u590d\u8fd9\u4e00\u8fc7\u7a0b<\/p>\n<p>\u5426\u5219\u5c31\u6267\u884c\u5faa\u73af\u4f53\u540e\u9762\u7684\u8bed\u53e5\u3002<\/p>\n<p>\u6362\u53e5\u8bdd\u8bf4\uff0c\u9664\u975ewhile\u8bed\u53e5\u5185\u7684\u6761\u4ef6\u8868\u8fbe\u5f0f\u4e3a\u5047\uff0c\u5426\u5219\u5faa\u73af\u4f53\u5c06\u88ab\u91cd\u590d\u8fd0\u884c\uff01<\/p>\n<p>\u4ee5\u4e0b\u9762\u8fd9\u4e2a\u7a0b\u5e8f\u4e3a\u4f8b\u5b50<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\nint main()\r\n{\r\n    int i = 0;\r\n    while (i &lt;= 100)\r\n    {\r\n        printf(&quot;%d\\n&quot;, i);\r\n        i = i + 1;\r\n    }\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u5b83\u5c06\u5728\u5c4f\u5e55\u4e0a\u6253\u53700 &#8211; 100\u4e00\u5171101\u4e2a\u6570\u5b57<\/p>\n<p>\u8fd9\u4e2a\u7a0b\u5e8f\u5e94\u8be5\u5f88\u597d\u7406\u89e3\uff0c\u7b2c\u4e03\u884c\u7a0b\u5e8f\u6267\u884c\u5230while\u5faa\u73af\uff0c\u6b64\u65f6i=0\uff0c\u663e\u7136\u8868\u8fbe\u5f0f\u4e3a\u771f<\/p>\n<p>\u56e0\u6b64\u5f00\u59cb\u6267\u884c\u5faa\u73af\u4f53\uff0c\u9996\u5148\u6253\u5370\u51fai\u53d8\u91cf\u7684\u503c\uff0c\u7136\u540e\u8ba9i\u672c\u8eab\u52a0\u4e0a1<\/p>\n<p>\u8fd9\u65f6i=1\uff0c\u8868\u8fbe\u5f0f\u4ecd\u7136\u4e3a\u771f\uff0c\u4e8e\u662f\u7a0b\u5e8f\u4ece\u5faa\u73af\u4f53\u7684\u5f00\u5934\u7ee7\u7eed\u6267\u884c\uff0c\u8fd9\u6b21\u5c06\u5411\u5c4f\u5e55\u6253\u5370\u6570\u5b571<\/p>\n<p>\u76f4\u5230\u6700\u540e\u4e00\u6b21\u5faa\u73af\uff0c\u6b64\u65f61=100\uff0c\u6ee1\u8db3\u6761\u4ef6\u8fdb\u5165\u5faa\u73af\u540e\u6253\u5370\u6570\u5b57\uff0c\u5e76\u4e14\u81ea\u589e\u3002\u7136\u540ei\u7684\u503c\u4fbf\u53d8\u6210\u4e86101\uff0c\u6b64\u65f6\u6761\u4ef6\u8868\u8fbe\u5f0f\u8fd4\u56de\u7684\u503c\u53d8\u6210\u4e86\u5047<\/p>\n<p>\u7a0b\u5e8f\u9000\u51fa\u5faa\u73af\uff0c\u6765\u5230return\u8bed\u53e5\uff0c\u7a0b\u5e8f\u9000\u51fa<\/p>\n<p>\u4f3c\u4e4e\u76ee\u524d\u5faa\u73af\u770b\u8d77\u6765\u5f88\u7b80\u5355\uff0c\u4f46\u662f\u4e0d\u8981\u5e86\u5e78\uff0c\u5faa\u73af\u7684\u52a0\u5165\u624d\u662f\u4f60\u5669\u68a6\u7684\u5f00\u59cb\uff01\u4ec0\u4e48\u5669\u68a6\uff1f\u6211\u4eec\u5230\u65f6\u5019\u5c31\u77e5\u9053\u4e86<\/p>\n<p>\u73b0\u5728\u518d\u56de\u5230\u4e0a\u9762\u6253\u5370\u6e29\u5ea6\u6362\u7b97\u8868\u7684\u7a0b\u5e8f\u4e0a\u6765<\/p>\n<p>\u6211\u4eec\u7b2c\u4e00\u4e2a\u9700\u8981\u8ba1\u7b97\u7684\u6e29\u5ea6\u662f0\u534e\u6c0f\u5ea6\uff0c\u6253\u5370\u5230100\u534e\u6c0f\u5ea6\u65f6\u505c\u6b62\uff0c\u56e0\u6b64\u6211\u4eec\u7684while\u5e94\u8be5\u662f\u8fd9\u6837\u7684<\/p>\n<p><em><strong>\u00a0while (Fdegree &lt;= 100)<\/strong><\/em><br \/>\n<em><strong>{<\/strong><\/em><br \/>\n<em><strong>}<\/strong><\/em><\/p>\n<p>\u534e\u6c0f\u5ea6\u8f6c\u6362\u4e3a\u6444\u6c0f\u5ea6\u7684\u516c\u5f0f\u662f\uff1a<strong>\u6444\u6c0f\u5ea6=(\u534e\u6c0f\u5ea6-32)\/1.8<\/strong><\/p>\n<p>\u8bf7\u53c2\u8003\u4e0a\u9762\u7684\u4f8b\u5b50\u81ea\u5df1\u5c06\u5faa\u73af\u4f53\u5199\u5b8c<\/p>\n<hr \/>\n<p>\u540c\u6837\u7684<\/p>\n<p>\u6211\u4eec\u5728\u6700\u540e\u7ed9\u51fa\u4e00\u4e2a\u53c2\u8003\u7684\u7a0b\u5e8f<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\nint main()\r\n{\r\n\u00a0\u00a0\u00a0 double Fahrenheit = 0, Celsius = 0;\r\n\u00a0\u00a0\u00a0 printf(&quot;\u6444\u6c0f\u5ea6\\t\u534e\u6c0f\u5ea6:\\n&quot;);\r\n\r\n\u00a0\u00a0\u00a0 while (Fahrenheit &lt;= 100)\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Celsius = (Fahrenheit - 32)\/1.8;\u00a0\u00a0 \/\/\u5c06\u534e\u6c0f\u5ea6\u6362\u7b97\u6210\u6444\u6c0f\u5ea6\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 printf(&quot;%.2f\\t%.2f\\n&quot;, Fahrenheit, Celsius);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Fahrenheit = Fahrenheit + 10;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 return 0;\r\n}\r\n\r\n<\/pre>\n<p>\u4f5c\u4e3a\u7ec3\u4e60\uff0c\u8bf7\u5c1d\u8bd5\u7740\u5c06\u7a0b\u5e8f\u4fee\u6539\u4e3a\u5c06\u6444\u6c0f\u5ea6\u8f6c\u6362\u4e3a\u534e\u6c0f\u5ea6\u7684\u529f\u80fd<\/p>\n<p>\u540c\u65f6\u8303\u56f4\u6539\u4e3a0-150\u6444\u6c0f\u5ea6\uff0c\u6b65\u957f\u6539\u4e3a5\u6444\u6c0f\u5ea6<span id=\"transmark\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8ba1\u7b97\u673a\u5f88\u64c5\u957f\u4e8e\u5e72\u91cd\u590d\u7684\u4e8b\u60c5\uff0c\u56e0\u4e3a\u4ed6\u6ca1\u6709\u60c5\u611f\uff0c\u5e76\u4e0d\u4f1a\u56e0\u4e3a\u91cd\u590d\u800c\u611f\u5230\u538c\u70e6\u3002 \u53ef\u4ee5\u8bf4\u7edd\u5927\u591a\u6570\u7a0b\u5e8f\u90fd\u4f1a\u7528\u5230\u5faa\u73af\uff01\u800c\u73b0\u5728\u2026 <span class=\"read-more\"><a href=\"https:\/\/yangwang.hk\/?p=457\">Read More: 3.3\u3001while\u5faa\u2026 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-c"],"views":2546,"_links":{"self":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=457"}],"version-history":[{"count":5,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":614,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions\/614"}],"wp:attachment":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}