add expressions-zh.md
This commit is contained in:
parent
574097924b
commit
357fa1bc24
|
@ -1,6 +1,6 @@
|
||||||
# Statements and Expressions
|
# 语句与表达式
|
||||||
|
|
||||||
### Examples
|
### 示例
|
||||||
```rust,editable
|
```rust,editable
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 5u32;
|
let x = 5u32;
|
||||||
|
@ -9,12 +9,12 @@ fn main() {
|
||||||
let x_squared = x * x;
|
let x_squared = x * x;
|
||||||
let x_cube = x_squared * x;
|
let x_cube = x_squared * x;
|
||||||
|
|
||||||
// This expression will be assigned to `y`
|
// 下面表达式的值将被赋给 `y`
|
||||||
x_cube + x_squared + x
|
x_cube + x_squared + x
|
||||||
};
|
};
|
||||||
|
|
||||||
let z = {
|
let z = {
|
||||||
// The semicolon suppresses this expression and `()` is assigned to `z`
|
// 分号让表达式变成了语句,因此返回的不再是表达式 `2 * x` 的值,而是语句的值 `()`
|
||||||
2 * x;
|
2 * x;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,10 +24,10 @@ fn main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### exercises
|
### 练习
|
||||||
🌟🌟
|
🌟🌟
|
||||||
```rust,editable
|
```rust,editable
|
||||||
// make it work with two ways: both modify the inner {}
|
// 使用两种方法修改内部的 {} 中的内容
|
||||||
fn main() {
|
fn main() {
|
||||||
let v = {
|
let v = {
|
||||||
let mut x = 1;
|
let mut x = 1;
|
||||||
|
|
Loading…
Reference in New Issue