知识卡片
按终止条件选择循环
while 适合每轮先检查 bool,while let 适合每轮取下一个 Option 等值,只要模式匹配就继续。for 适合遍历 IntoIterator 支持的输入,例如 0..20;loop 没有进入条件,适合在循环体中确定停止位置。while、while let 和 for 的结果是 (),loop 可以由 break 提供结果。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Expressions 按终止条件和所有权选择循环 · 查看原书依据
At the beginning of each loop iteration, the value of expr either matches the given pattern, in which case the block runs
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第05章《Expressions》|按终止条件和所有权选择循环,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch05.xhtml#loops`
- 结论依据:原文分别说明四种循环的开始和终止方式,并解释只有 loop 型循环可用 break 产生值。
- 原始内容:At the beginning of each loop iteration, the value of expr either matches the given pattern, in which case the block runs