\r\nb \u4e3a 1<\/pre>\nRust \u4e2d\u7684\u6761\u4ef6\u8868\u8fbe\u5f0f\u5fc5\u987b\u662f bool \u7c7b\u578b\uff0c\u4f8b\u5982\u4e0b\u9762\u7684\u7a0b\u5e8f\u662f\u9519\u8bef\u7684\uff1a<\/p>\n
\r\nfn main() { \r\n let number = 3; \r\n if number { \/\/ \u62a5\u9519\uff0cexpected `bool`, found integerrustc(E0308)\r\n println!(\"Yes\");\r\n } \r\n} <\/pre>\n\u867d\u7136 C\/C++ \u8bed\u8a00\u4e2d\u7684\u6761\u4ef6\u8868\u8fbe\u5f0f\u7528\u6574\u6570\u8868\u793a\uff0c\u975e 0 \u5373\u771f\uff0c\u4f46\u8fd9\u4e2a\u89c4\u5219\u5728\u5f88\u591a\u6ce8\u91cd\u4ee3\u7801\u5b89\u5168\u6027\u7684\u8bed\u8a00\u4e2d\u662f\u88ab\u7981\u6b62\u7684\u3002<\/p>\n
\u7ed3\u5408\u4e4b\u524d\u7ae0\u5b66\u4e60\u7684\u51fd\u6570\u4f53\u8868\u8fbe\u5f0f\u6211\u4eec\u52a0\u4ee5\u8054\u60f3\uff1a<\/p>\n
\r\nif { block 1 } else { block 2 } <\/condition><\/pre>\n\u8fd9\u79cd\u8bed\u6cd5\u4e2d\u7684 { block 1 } \u548c { block 2 } \u53ef\u4e0d\u53ef\u4ee5\u662f\u51fd\u6570\u4f53\u8868\u8fbe\u5f0f\u5462\uff1f<\/p>\n
\u7b54\u6848\u662f\u80af\u5b9a\u7684\uff01\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728 Rust \u4e2d\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 if-else \u7ed3\u6784\u5b9e\u73b0\u7c7b\u4f3c\u4e8e\u4e09\u5143\u6761\u4ef6\u8fd0\u7b97\u8868\u8fbe\u5f0f (A ? B : C) \u7684\u6548\u679c\uff1a<\/p>\n
\u5b9e\u4f8b<\/p>\n
\r\nfn main() {\r\n let a = 3;\r\n let number = if a > 0 { 1 } else { -1 };\r\n println!(\"number \u4e3a {}\", number);\r\n}<\/pre>\n\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n
\r\nnumber \u4e3a 1<\/pre>\n\u6ce8\u610f\uff1a\u4e24\u4e2a\u51fd\u6570\u4f53\u8868\u8fbe\u5f0f\u7684\u7c7b\u578b\u5fc5\u987b\u4e00\u6837\uff01\u4e14\u5fc5\u987b\u6709\u4e00\u4e2a else \u53ca\u5176\u540e\u7684\u8868\u8fbe\u5f0f\u5757\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5728 Rust \u8bed\u8a00\u4e2d\u7684\u6761\u4ef6\u8bed\u53e5\u4f7f\u8fd9\u79cd\u683c\u5f0f\u7684\uff1a \u5b9e\u4f8b fn main() { let number = 3; i […]<\/p>\n","protected":false},"author":1470,"featured_media":205801,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-205810","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=205810"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205810\/revisions"}],"predecessor-version":[{"id":205813,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/205810\/revisions\/205813"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/205801"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=205810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=205810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=205810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}