Skip to content

Commit

Permalink
Merge pull request #302 from cos800/patch-1
Browse files Browse the repository at this point in the history
Update control-flow.md
  • Loading branch information
hltj authored Mar 17, 2024
2 parents e68270b + 66cfda0 commit 61d8298
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/topics/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ fun main() {

## while 循环

`while` and `do-while` loops execute their body continuously while their condition is satisfied.
The difference between them is the condition checking time:
* `while` checks the condition and, if it's satisfied, executes the body and then returns to the condition check.
* `do-while` executes the body and then checks the condition. If it's satisfied, the loop repeats. So, the body of `do-while`
executes at least once regardless of the condition.
`while` `do-while` 当循环条件满足时会持续执行它们的主体。
它们之间的区别在于条件检查的时间:
* `while` 先检查条件,如果满足,则执行主体,然后再返回到条件检查。
* `do-while` 先执行主体,然后检查条件。如果满足,则循环重复。
所以 `do-while` 的主体至少执行一次,不管条件如何。

```kotlin
while (x > 0) {
Expand Down

0 comments on commit 61d8298

Please sign in to comment.