Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-jerry-ye authored Mar 4, 2024
1 parent 051ba14 commit fefff96
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions zh-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,6 @@ while i < 10 {
println(n) // outputs 25
```

`while` 循环还可以有一个可选的 "continue" 块。"continue" 块位于循环条件和循环体之间,和循环条件用逗号分隔。它会在每次循环的循环体之后、下一次循环的循环条件之前被执行:

```rust
let mut i = 0
while i < 10, i = i + 1 {
println(i)
} // outputs 0 to 9
```

如果在一个 "continue" 块里有多个语句,它们需要被花括号包裹。循环体中的 `continue` 语句不会跳过 "continue" 块。例如,下面的例子会输出小于 10 的所有奇数:

```rust
let mut i = 1
while i < 10, i = i + 1 {
if (i % 2 == 0) {
continue
}
println(i)
} // outputs 1 3 5 7 9
```

## 内置数据结构

### 布尔值
Expand Down Expand Up @@ -916,8 +895,9 @@ fn init {
let fox1 = Fox::make("fox1")
let animals = [ duck1 as Animal, duck2 as Animal, fox1 as Animal ]
let mut i = 0
while i < animals.length(), i = i + 1 {
while i < animals.length() {
animals[i].speak()
i = i + 1
}
}
```
Expand Down

0 comments on commit fefff96

Please sign in to comment.