← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 10881 · 生成模型:未记录

控制流要求布尔表达式

理解等级:初级

if、while、&&、|| 只接受 bool 条件。想检查计数是否非零,写 if n != 0,使读者能看见判定标准。用 as 可把 false、true 分别转为整数 0 和 1;从整数判断真或假需要比较。每个 bool 在内存中独占一个字节,可取其地址。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《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