知识卡片
loop退出可带结果
loop 在体内通过 break value 结束时,可以把该值作为整个循环表达式的结果。比如一直寻找满足条件的元素,找到后直接返回它给外层绑定。嵌套循环可用标签指明 break 或 continue 的目标。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 常见编程概念 Repetition with Loops · 查看原书依据
One of the uses of a loop is to retry an operation you know might fail, such as checking whether a thread has completed its job. You might also need to pass the result of that operation out of the loop to the rest of your code.
参考来源
- 位置:《The Rust Programming Language(第2版)》第03章 常见编程概念(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c03.xhtml`,块 0288)
- 结论依据:原文用 break 返回值表达重复尝试后得到的结果。
- 原始内容:One of the uses of a loop is to retry an operation you know might fail, such as checking whether a thread has completed its job. You might also need to pass the result of that operation out of the loop to the rest of your code.