{"id":519,"date":"2018-02-23T23:38:57","date_gmt":"2018-02-23T15:38:57","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/swift-%e5%b5%8c%e5%a5%97-if-%e8%af%ad%e5%8f%a5\/"},"modified":"2018-02-23T23:38:57","modified_gmt":"2018-02-23T15:38:57","slug":"swift-%e5%b5%8c%e5%a5%97-if-%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=519","title":{"rendered":"Swift \u5d4c\u5957 if \u8bed\u53e5"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>Swift <span class=\"color_h1\">\u5d4c\u5957 if \u8bed\u53e5<\/span><\/h1>\n<p><a href=\"\/swift-decision-making.html\"><img decoding=\"async\" class=\"navup\" src=\"\/images\/up.gif\" alt=\"Swift \u6761\u4ef6\u8bed\u53e5\">Swift \u6761\u4ef6\u8bed\u53e5<\/a><\/p>\n<p>\u5728 Swift \u8bed\u8a00\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a if \u6216 else if \u8bed\u53e5\u5185\u4f7f\u7528\u53e6\u4e00\u4e2a if \u6216 else if \u8bed\u53e5\u3002<\/p>\n<hr>\n<h2>\u8bed\u6cd5<\/h2>\n<p>Swift \u8bed\u8a00\u4e2d \u5d4c\u5957 if \u8bed\u53e5\u7684\u8bed\u6cd5\uff1a<\/p>\n<pre>\nif boolean_expression_1 {\n   \/* \u5f53 boolean_expression_1 \u8868\u8fbe\u5f0f true \u65f6\u6267\u884c *\/\n   if boolean_expression_2 {\n      \/* \u5f53 boolean_expression_1 \u8868\u8fbe\u5f0f true \u65f6\u6267\u884c *\/\n   }\n}\n<\/pre>\n<p>\u60a8\u53ef\u4ee5\u5d4c\u5957 <b>else if&#8230;else<\/b>\uff0c\u65b9\u5f0f\u4e0e\u5d4c\u5957 <i>if<\/i> \u8bed\u53e5\u76f8\u4f3c\u3002<\/p>\n<h3>\u5b9e\u4f8b<\/h3>\n<pre>\nimport Cocoa\n\nvar varA:Int = 100;\nvar varB:Int = 200;\n\n\/* \u68c0\u6d4b\u5e03\u5c14\u6761\u4ef6 *\/\nif varA == 100 {\n   \/* \u5982\u679c\u6761\u4ef6\u4e3a true \u6267\u884c\u4ee5\u4e0b\u8bed\u53e5 *\/\n   print(\"\u7b2c\u4e00\u4e2a\u6761\u4ef6\u4e3a true\");\n\u00a0\u00a0\u00a0\u00a0\n   if varB == 200 {\n      \/* \u5982\u679c\u6761\u4ef6\u4e3a true \u6267\u884c\u4ee5\u4e0b\u8bed\u53e5 *\/\n      print(\"\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u4e5f\u662f true\");\n   } \n}\nprint(\"varA \u53d8\u91cf\u7684\u503c\u4e3a \\(varA)\");\nprint(\"varB \u53d8\u91cf\u7684\u503c\u4e3a \\(varB)\");\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>\n\u7b2c\u4e00\u4e2a\u6761\u4ef6\u4e3a true\n\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u4e5f\u662f true\nvarA \u53d8\u91cf\u7684\u503c\u4e3a 100\nvarB \u53d8\u91cf\u7684\u503c\u4e3a 200\n<\/pre>\n<p><a href=\"\/swift-decision-making.html\"><img decoding=\"async\" class=\"navup\" src=\"\/images\/up.gif\" alt=\"Swift \u6761\u4ef6\u8bed\u53e5\">Swift \u6761\u4ef6\u8bed\u53e5<\/a><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">Swift \u5d4c\u5957 if \u8bed\u53e5 Swift \u6761\u4ef6\u8bed\u53e5 \u5728 Swift \u8bed\u8a00\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a &hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=519\">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-519","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\/519","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=519"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/519\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}