{"id":528,"date":"2018-02-23T23:39:01","date_gmt":"2018-02-23T15:39:01","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/swift-fallthrough-%e8%af%ad%e5%8f%a5\/"},"modified":"2018-02-23T23:39:01","modified_gmt":"2018-02-23T15:39:01","slug":"swift-fallthrough-%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=528","title":{"rendered":"Swift Fallthrough \u8bed\u53e5"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>Swift Fallthrough \u8bed\u53e5<\/h1>\n<p><a href=\"\/swift-loops.html\"><img decoding=\"async\" class=\"navup\" src=\"\/images\/up.gif\" alt=\"Swift \u5faa\u73af\">Swift \u5faa\u73af<\/a><\/p>\n<p>Swift fallthrough \u8bed\u53e5\u8ba9 case \u4e4b\u540e\u7684\u8bed\u53e5\u4f1a\u6309\u987a\u5e8f\u7ee7\u7eed\u8fd0\u884c\uff0c\u4e14\u4e0d\u8bba\u6761\u4ef6\u662f\u5426\u6ee1\u8db3\u90fd\u4f1a\u6267\u884c\u3002<\/p>\n<p>Swift \u4e2d\u7684 switch \u4e0d\u4f1a\u4ece\u4e0a\u4e00\u4e2a case \u5206\u652f\u843d\u5165\u5230\u4e0b\u4e00\u4e2a case \u5206\u652f\u4e2d\u3002\u53ea\u8981\u7b2c\u4e00\u4e2a\u5339\u914d\u5230\u7684 case \u5206\u652f\u5b8c\u6210\u4e86\u5b83\u9700\u8981\u6267\u884c\u7684\u8bed\u53e5\uff0c\u6574\u4e2aswitch\u4ee3\u7801\u5757\u5b8c\u6210\u4e86\u5b83\u7684\u6267\u884c\u3002<\/p>\n<blockquote>\n<p><b>\u6ce8\u610f\uff1a<\/b>\u5728\u5927\u591a\u6570\u8bed\u8a00\u4e2d\uff0cswitch \u8bed\u53e5\u5757\u4e2d\uff0ccase \u8981\u7d27\u8ddf break\uff0c\u5426\u5219 case \u4e4b\u540e\u7684\u8bed\u53e5\u4f1a\u987a\u5e8f\u8fd0\u884c\uff0c\u800c\u5728 Swift \u8bed\u8a00\u4e2d\uff0c\u9ed8\u8ba4\u662f\u4e0d\u4f1a\u6267\u884c\u4e0b\u53bb\u7684\uff0cswitch \u4e5f\u4f1a\u7ec8\u6b62\u3002\u5982\u679c\u4f60\u60f3\u5728 Swift \u4e2d\u8ba9 case \u4e4b\u540e\u7684\u8bed\u53e5\u4f1a\u6309\u987a\u5e8f\u7ee7\u7eed\u8fd0\u884c\uff0c\u5219\u9700\u8981\u4f7f\u7528 fallthrough \u8bed\u53e5\u3002<\/p>\n<\/blockquote>\n<h3>\u8bed\u6cd5<\/h3>\n<p>Swift fallthrough \u8bed\u53e5\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>\nfallthrough\n<\/pre>\n<p>\u4e00\u822c\u5728 switch \u8bed\u53e5\u4e2d\u4e0d\u4f7f\u7528 fallthrough \u8bed\u53e5\u3002<\/p>\n<h3>\u5b9e\u4f8b1<\/h3>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6ca1\u6709\u4f7f\u7528 fallthrough \u8bed\u53e5\uff1a<\/p>\n<pre>\nimport Cocoa\n\nvar index = 10\n\nswitch index {\n   case 100  :\n      print( \"index \u7684\u503c\u4e3a 100\")\n   case 10,15  :\n      print( \"index \u7684\u503c\u4e3a 10 \u6216 15\")\n   case 5  :\n      print( \"index \u7684\u503c\u4e3a 5\")\n   default :\n      print( \"\u9ed8\u8ba4 case\")\n}\n<\/pre>\n<p>\u5f53\u4e0a\u9762\u7684\u4ee3\u7801\u88ab\u7f16\u8bd1\u6267\u884c\u65f6\uff0c\u5b83\u4f1a\u4ea7\u751f\u4e0b\u5217\u7ed3\u679c\uff1a<\/p>\n<pre>\nindex \u7684\u503c\u4e3a 10 \u6216 15\n<\/pre>\n<h3>\u5b9e\u4f8b2<\/h3>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u4f7f\u7528 fallthrough \u8bed\u53e5\uff1a<\/p>\n<pre>\nimport Cocoa\n\nvar index = 10\n\nswitch index {\n   case 100  :\n      print( \"index \u7684\u503c\u4e3a 100\")\n      fallthrough\n   case 10,15  :\n      print( \"index \u7684\u503c\u4e3a 10 \u6216 15\")\n      fallthrough\n   case 5  :\n      print( \"index \u7684\u503c\u4e3a 5\")\n   default :\n      print( \"\u9ed8\u8ba4 case\")\n}\n<\/pre>\n<p>\u5f53\u4e0a\u9762\u7684\u4ee3\u7801\u88ab\u7f16\u8bd1\u6267\u884c\u65f6\uff0c\u5b83\u4f1a\u4ea7\u751f\u4e0b\u5217\u7ed3\u679c\uff1a<\/p>\n<pre>\nindex \u7684\u503c\u4e3a 10 \u6216 15\nindex \u7684\u503c\u4e3a 5\n<\/pre>\n<p><a href=\"\/swift-loops.html\"><img decoding=\"async\" class=\"navup\" src=\"\/images\/up.gif\" alt=\"Swift \u5faa\u73af\">Swift \u5faa\u73af<\/a><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">Swift Fallthrough \u8bed\u53e5 Swift \u5faa\u73af Swift fallthrou&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=528\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,28],"tags":[74,119],"class_list":["post-528","post","type-post","status-publish","format-standard","hentry","category-mobile","category-swift","tag-ios","tag-swift","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=528"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/528\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}