{"id":140,"date":"2022-08-06T12:55:41","date_gmt":"2022-08-06T04:55:41","guid":{"rendered":"http:\/\/www.zhangxiaohei.cn\/?p=140"},"modified":"2022-08-06T12:55:41","modified_gmt":"2022-08-06T04:55:41","slug":"%e5%85%adc%e8%af%ad%e8%a8%80%e6%95%99%e7%a8%8bcontinue%ef%bc%8cbreak%e5%92%8cswitch-case","status":"publish","type":"post","link":"http:\/\/www.zhangxiaohei.cn\/?p=140","title":{"rendered":"(\u516d)C\u8bed\u8a00\u6559\u7a0b&#038;continue\uff0cbreak\u548cswitch-case"},"content":{"rendered":"\n<p>continue\u8fd8\u662f\u5f88\u597d\u7406\u89e3\u7684\uff0c&#8221;\u7ee7\u7eed\uff0c\u63a5\u7740&#8221;\uff0c\u5728C\u8bed\u8a00\u91cc\u5c31\u662f\u8df3\u8fc7\u672c\u6b21\u5faa\u73af\u91cc\u672a\u6267\u884c\u7684\u8bed\u53e5\uff0c\u8fdb\u884c\u4e0b\u4e00\u6b21\u5faa\u73af\uff0c\u8bfb\u4e0d\u61c2\u7684\u54ac\u6587\u56bc\u5b57\u7684\u7422\u78e8\u7422\u78e8<\/p>\n\n\n\n<p>\u7ed9\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u53ef\u80fd\u66f4\u76f4\u63a5\u70b9\uff1a<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">include<\/h1>\n\n\n\n<p>int main(){<\/p>\n\n\n\n<p>&nbsp; &nbsp; for(int i=1;i&lt;=10;i++){<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;%d\\n&#8221;,i);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p>\u5982\u679c\u52a0\u4e0a\u4e2acontinue\uff0c\u628a\u4ee3\u7801\u53d8\u6210\u8fd9\u6837\uff1a<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">include<\/h1>\n\n\n\n<p>int main(){<\/p>\n\n\n\n<p>&nbsp; &nbsp; for(int i=1;i&lt;=10;i++){<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if(i==3)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/\u4ece\u8fd9\u91cc\u5f00\u59cb\u52a0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/\u5230\u8fd9\u91cc\u7ed3\u675f<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;%d\\n&#8221;,i);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u8fd0\u884c\u7ed3\u679c\u5c31\u53d8\u6210\u8fd9\u6837\u4e86\uff1a<\/p>\n\n\n\n<p>\u5c11\u4e86\u4e00\u4e2a3<br>\u662f\u4e0d\u662f\u5c11\u4e86\u4e2a 3\uff0c\u5b83\u7684\u8fd0\u884c\u5c31\u662f\u8fd9\u6837\u7684\uff0c<\/p>\n\n\n\n<p>\u5f53 i=1\u65f6\uff0ci \u4e0d\u7b49\u4e8e3\uff0c\u76f4\u63a5\u8f93\u51fa1\uff0c<br>\u2026<br>\u5f53 i=3\u65f6\uff0ci \u6b63\u597d\u7b49\u4e8e3\uff0c\u6267\u884ccontinue\uff0c\u8df3\u8fc7\u540e\u9762\u5faa\u73af\u7684printf\uff0c\u5c31\u4e0d\u8f93\u51fa\u4e86<br>\u5f53 i=4\u65f6\uff0ci \u53c8\u4e0d\u7b49\u4e8e3\u4e86\uff0c\u7ee7\u7eed\u8f93\u51fa4<br>\u2026<\/p>\n\n\n\n<p>\u5176\u5b9e\u5e76\u4e0d\u96be\u7406\u89e3\uff0c\u81ea\u5df1\u8bd5\u4e00\u8bd5\u4fbf\u53ef\u4ee5\u660e\u767d\u900f\u5f7b<\/p>\n\n\n\n<p>\u7136\u540e\u5c31\u5230\u6211\u4eec\u4eca\u5929\u4e3b\u4f53\u7684\u53e6\u4e00\u4e2a\uff1abreak\u4e86<\/p>\n\n\n\n<p>break\uff0c\u672c\u610f\u6253\u7834\uff0c\u95f4\u65ad\uff0cC\u8bed\u8a00\u91cc\u4e5f\u5dee\u4e0d\u591a\uff0c\u5c31\u662f\u9000\u51fa\u5faa\u73af\uff0c\u540e\u9762\u7684\u6240\u6709\u5faa\u73af\u90fd\u4e0d\u6267\u884c\uff0c\u8fd8\u662f\u4e0a\u9762\u90a3\u4e2a\u4f8b\u5b50\uff0c\u628acontinue\u6362\u4e3abreak\uff1a<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">include<\/h1>\n\n\n\n<p>int main(){<\/p>\n\n\n\n<p>&nbsp; &nbsp; for(int i=1;i&lt;=10;i++){<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if(i==3)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; \/\/\u53ea\u6362\u4e86\u8fd9\u4e00\u884c<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;%d\\n&#8221;,i);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p>\u6253\u65ad\u65bd\u6cd5(<br>\u53ef\u4ee5\u770b\u51fa\uff0ci=3\u4ee5\u540e\u7684\u6240\u6709\u5faa\u73af\u90fd\u4e0d\u6267\u884c\u4e86\uff0c\u53ea\u8f93\u51fa\u4e861\uff0c2<\/p>\n\n\n\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u5e94\u8be5\u80fd\u7406\u89e3continue\u548cbreak\u7684\u533a\u522b\u4e86\u5427\uff0c\u4e0d\u660e\u767d\u5c31\u81ea\u5df1\u591a\u4e3e\u51e0\u4e2a\u4f8b\u5b50<\/p>\n\n\n\n<p>\u6bd4\u5982\u8f93\u51fa\u4e00\u5230\u5341\u7684\u5947\u6570\u6216\u5076\u6570\uff0c\u4e5f\u53ef\u4ee5\u7528continue\u6765\u5b9e\u73b0<\/p>\n\n\n\n<p>\u4e0b\u9762\u54b1\u6765\u8bb2\u8bb2switch-case\u7ed3\u6784<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u4e5f\u662fC\u8bed\u8a00\u91cd\u70b9\u4e4b\u4e00\u7684\u554a\uff0c\u90fd\u8bb0\u4f4f\u55bd\uff0c\u62ff\u51fa\u5c0f\u672c\u672c\u6765\u8bb0<\/p>\n\n\n\n<p>switch-case \u662f\u4e00\u79cd\u7c7b\u4f3c\u4e0e if-else if \u7684\u8bed\u53e5\uff0c\u5176\u5b9e\u4e8c\u8005\u5728\u5927\u591a\u60c5\u51b5\u4e0b\u90fd\u53ef\u4ee5\u4e92\u76f8\u8f6c\u6362\uff0c\u4f46\u662fswitch\u662f\u7ecf\u5e38\u548cbreak\u8fde\u7528\u7684\uff0c\u4e00\u822c\u60c5\u51b5\u90fd\u9700\u8981<\/p>\n\n\n\n<p>\u5148\u5199\u4e2a\u4f8b\u5b50\u5427\uff0c\u6bd4\u5982\uff0c\u4f60\u8f93\u5165\u4e00\u4e2a\u5c0f\u5199\u6570\u5b57\uff0c\u8f93\u51fa\u5b83\u7684\u5927\u5199\u5f62\u5f0f\uff08\u4e3a\u4e86\u65b9\u4fbf\uff0c\u8fd9\u91cc\u5c31\u53d61\uff0c2\uff0c3\u4e09\u4e2a\u6570\u5b57\uff09<\/p>\n\n\n\n<p>\u5148\u4e0a if \u683c\u5f0f\u7684\uff1a<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">include<\/h1>\n\n\n\n<p>int main()<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp; &nbsp; int num;<\/p>\n\n\n\n<p>&nbsp; &nbsp; scanf(&#8220;%d&#8221;,&amp;num);<\/p>\n\n\n\n<p>&nbsp; &nbsp; if(num==1)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u58f9\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; else if(num==2)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u8d30\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; else if(num==3)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u53c1\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u5f88\u6b63\u5e38\u5bf9\u4e0d\u5bf9\uff0c\u63a5\u4e0b\u6765\u770b\u770b switch-case \u683c\u5f0f\u7684\uff1a<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">include<\/h1>\n\n\n\n<p>int main()<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp; &nbsp; int num;<\/p>\n\n\n\n<p>&nbsp; &nbsp; scanf(&#8220;%d&#8221;,&amp;num);<\/p>\n\n\n\n<p>&nbsp; &nbsp; switch(num){<\/p>\n\n\n\n<p>case 1:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u58f9\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; break;<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; case 2:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u8d30\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; break;<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; case 3:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;\u53c1\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; break;<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p>\u5e94\u8be5\u770b\u7684\u660e\u767d\u5427\uff0cswitch( a )\uff0c\u5c31\u662f\u4f60\u8981\u5224\u65ad a\uff0c\u540e\u9762\u7684case\u5c31\u662f\u5f53a=\u51e0\u65f6\u6267\u884c\u7684\u8bed\u53e5\uff0c\u6bd4\u5982case 1\uff1a\uff0c\u5c31\u662f\u5f53a=1\u65f6\uff0c\u540e\u9762\u52a0\u4e0a\u4f60\u9700\u8981\u6267\u884c\u7684\u8bed\u53e5\uff0c\u6700\u540e\u4e00\u5b9a\u8981\u52a0\u4e00\u4e2abreak\uff0c\u4e0d\u7136\u5c31\u4f1a\u6267\u884c\u540e\u9762\u6240\u6709\u7684case\uff0c\u6bd4\u5982\u53bb\u6389\u8fd9\u4e2a\u4f8b\u5b50\u91cc\u7684break\uff0c\u6267\u884c\u7ed3\u679c\u5c31\u662f\u8fd9\u6837\uff1a<\/p>\n\n\n\n<p>\u6240\u4ee5\u4e00\u5b9a\u8981\u8bb0\u5f97\u52a0\u4e0abreak (\u5927\u591a\u6570\u60c5\u51b5)\uff0c\u53e6\u5916\u4f60\u4e5f\u53ef\u4ee5\u5728\u6700\u540e\u52a0\u4e00\u4e2adefault:\uff0c\u8fd9\u4e2a\u91cc\u9762\u4e0d\u9700\u8981\u52a0break\uff0c\u5b83\u5c31\u662f\u5176\u4ed6\u7684\u610f\u601d\uff0c\u6240\u4ee5switch\u57fa\u672c\u683c\u5f0f\u5c31\u662f\u8fd9\u6837\uff1a<\/p>\n\n\n\n<p>switch(a){<\/p>\n\n\n\n<p>&nbsp; &nbsp; case 1:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/TODO<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; break;<\/p>\n\n\n\n<p>&nbsp; &nbsp; case 2:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/TODO<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; break;<\/p>\n\n\n\n<p>&nbsp; &nbsp; \u2026<\/p>\n\n\n\n<p>&nbsp; &nbsp; default:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/TODO<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u5176\u5b9eswitch\u5b8c\u5168\u53ef\u4ee5\u88ab if else\u4ee3\u66ff\uff0c\u4f46\u662f\u8c8c\u4f3c\u8fd9\u6837\u5199\u6bd4\u5012\u91d1\u5b57\u5854\u597d\u770b\u70b9\uff0c\u5e76\u4e14\u7b80\u5355\u660e\u4e86\uff0c\u591a\u79cd\u60c5\u51b5\u8fd8\u662f\u5efa\u8bae\u7528\u7684<\/p>\n\n\n\n<p>\u597d\u4e86\uff0c\u4eca\u5929\u5c31\u8bb2\u5230\u8fd9\u91cc\u5427\uff0c\u53e6\u5916\uff0c\u518d\u5e03\u7f6e\u4e00\u70b9\u5c0f\u4f5c\u4e1a\uff0c\u9898\u76ee\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u8f93\u5165\u6570\u5b66\u8868\u8fbe\u5f0f\uff08\u5f62\u4f3c1+1\uff09\uff0c\u6570\u5b57\u4e3a\u6574\u6570\uff0c\u7b26\u53f7\u4ec5\u9650+ &#8211; * \/\uff0c\u4e14\u5f53\u7b26\u53f7\u4e3a \/ \u65f6\uff0c\u9664\u6570\u4e0d\u4e3a\u96f6\uff0c\u8f93\u51fa\u6b64\u6570\u5b66\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c(\u59821+1\u8f93\u51fa2)<\/p>\n\n\n\n<p>\u8fd9\u662f\u4e0a\u6b21\u9898\u7684\u7b54\u6848\uff1a<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">include<\/h1>\n\n\n\n<p>int main(){<\/p>\n\n\n\n<p>&nbsp; &nbsp; int num,a;<\/p>\n\n\n\n<p>a=1;<\/p>\n\n\n\n<p>printf(&#8220;\u8bf7\u8f93\u5165\u4e00\u4e2a\u6570\u5b57\uff1a&#8221;);<\/p>\n\n\n\n<p>scanf(&#8220;%d&#8221;,&amp;num);<\/p>\n\n\n\n<p>for(int i=2;a==1&amp;&amp;i&lt;=num-1;i++){<\/p>\n\n\n\n<p>if(num%i==0)&nbsp; &nbsp; &nbsp; \/\/\u8c8c\u4f3c\u6ca1\u8bf4\u8fc7%\u7684\u610f\u601d\uff0c\u8fd9\u4e2a\u5c31\u662f\u53d6\u4f59\uff0c\u5c31\u662f\u4f59\u6570\uff0c\u6bd4\u59822%1\u5c31\u662f0\uff0c<\/p>\n\n\n\n<p>a=0;&nbsp; &nbsp; &nbsp; \/\/\u800c3%2\u5c31\u662f1\uff0c\u56e0\u4e3a3\/2=1\u20261<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>if(a==1)<\/p>\n\n\n\n<p>printf(&#8220;\u8fd9\u4e2a\u6570\u662f\u8d28\u6570\\n&#8221;);<\/p>\n\n\n\n<p>else<\/p>\n\n\n\n<p>printf(&#8220;\u8fd9\u4e2a\u6570\u662f\u5408\u6570\\n&#8221;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; return 0;<\/p>\n\n\n\n<p>}  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>continue\u8fd8\u662f\u5f88\u597d\u7406\u89e3\u7684\uff0c&#8221;\u7ee7\u7eed\uff0c\u63a5\u7740&#8221;\uff0c\u5728C\u8bed\u8a00\u91cc\u5c31\u662f\u8df3\u8fc7\u672c\u6b21\u5faa\u73af\u91cc\u672a\u6267\u884c\u7684\u8bed<\/p><\/div>\n<div class=\"blog-btn\"><a href=\"http:\/\/www.zhangxiaohei.cn\/?p=140\" class=\"home-blog-btn\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=140"}],"version-history":[{"count":0,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts\/140\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}