diff --git a/translated/tech/20230501.1 ⭐️⭐️ Rust Basics Series 6 Conditional Statements.md b/published/20230501.1 ⭐️⭐️ Rust Basics Series 6 Conditional Statements.md similarity index 87% rename from translated/tech/20230501.1 ⭐️⭐️ Rust Basics Series 6 Conditional Statements.md rename to published/20230501.1 ⭐️⭐️ Rust Basics Series 6 Conditional Statements.md index 5cbc24b757..cce5726762 100644 --- a/translated/tech/20230501.1 ⭐️⭐️ Rust Basics Series 6 Conditional Statements.md +++ b/published/20230501.1 ⭐️⭐️ Rust Basics Series 6 Conditional Statements.md @@ -3,18 +3,20 @@ [#]: author: "Pratham Patel https://itsfoss.com/author/pratham/" [#]: collector: "lkxed" [#]: translator: "Cubik65536" -[#]: reviewer: " " -[#]: publisher: " " -[#]: url: " " +[#]: reviewer: "wxy" +[#]: publisher: "wxy" +[#]: url: "https://linux.cn/article-15896-1.html" Rust 基础系列 #6: 条件语句 ====== +![][0] + 在 [上一篇文章][1] 中,你学习了函数。在这篇文章中,我们将学习使用条件语句来管理 Rust 程序的控制流。 ### 什么是条件语句? -在编写代码的时候,最常见的任务之一就是检查某些条件是否为 `true` 或 `false`。"如果温度高于 35°C,打开空调。" +在编写代码的时候,最常见的任务之一就是检查某些条件是否为 `true` 或 `false`。“如果温度高于 35°C,打开空调。” 通过使用 `if` 和 `else` 这样的关键字(有时候结合使用),程序员可以根据条件(例如提供的参数数量、从命令行传递的选项、文件名、错误发生等)改变程序的行为。 @@ -37,9 +39,9 @@ Rust 基础系列 #6: 条件语句 | 运算符 | 示例 | 解释 | | :- | :- | :- | -| `||` (逻辑或) | `条件1 || 条件2` | `条件1` 或 `条件2` 中至少有一个为 `true` | -| `&&` (逻辑与) | `条件1 && 条件2` | **所有** 条件都为 `true` | -| `!` (逻辑非) | `!条件` | `条件` 的布尔值的相反值 | +| `||` (逻辑或) | `条件1 || 条件2` | `条件1` 或 `条件2` 中至少有一个为 `true` | +| `&&` (逻辑与) | `条件1 && 条件2` | **所有** 条件都为 `true` | +| `!` (逻辑非) | `!条件` | `条件` 的布尔值的相反值 | > 📋 与数学相似,你可以使用圆括号来指定操作的优先级。 @@ -100,7 +102,7 @@ b 大于 a 但是这可以改进!我们继续。 -### 使用 'else if' 条件 +### 使用 else if 条件 与其他任何编程语言一样,你可以使用 `else if` 块来提供多于两个的执行路径。语法如下: @@ -183,10 +185,12 @@ a 是最大的 ### 总结 -你学习到了如何使用 if 和 else 语句。在你继续使用大量 if else-if 语句制作自己的 AI 之前(哈哈),让我们在本系列的下一篇文章中学习 Rust 中的循环。 +你学习到了如何使用 `if` 和 `else` 语句。在你继续使用大量 `if` `else if` 语句制作自己的 AI 之前(哈哈),让我们在本系列的下一篇文章中学习 Rust 中的循环。 持续关注。 +*(题图:MJ/3eea3bbb-b630-4470-ae21-391ab86cd5bf)* + -------------------------------------------------------------------------------- via: https://itsfoss.com/rust-if-else/ @@ -194,10 +198,11 @@ via: https://itsfoss.com/rust-if-else/ 作者:[Pratham Patel][a] 选题:[lkxed][b] 译者:[Cubik65536](https://github.com/Cubik65536) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 [a]: https://itsfoss.com/author/pratham/ [b]: https://github.com/lkxed/ [1]: https://linux.cn/article-15855-1.html +[0]: https://img.linux.net.cn/data/attachment/album/202306/11/094832bkkbs7oxntx7zxas.jpg \ No newline at end of file