知识卡片
控制流要求布尔表达式
if、while、&&、|| 只接受 bool 条件。想检查计数是否非零,写 if n != 0,使读者能看见判定标准。用 as 可把 false、true 分别转为整数 0 和 1;从整数判断真或假需要比较。每个 bool 在内存中独占一个字节,可取其地址。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Fundamental Types 布尔条件需要显式判定 · 查看原书依据
very strict: control structures like if and while require their conditions to be bool expressions, as do the short-circuiting logical operators && and ||. You
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|布尔条件需要显式判定,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#the-bool-type`
- 结论依据:原文对照其它语言的隐式真值规则,给出显式比较、转换方向以及字节存储解释。
- 原始内容:very strict: control structures like if and while require their conditions to be bool expressions, as do the short-circuiting logical operators && and ||. You