freeCodeCamp/guide/chinese/cplusplus/do-while-loop/index.md

43 lines
1007 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: do while loop
localeTitle: 做循环
---
## 做循环
`do while loop`几乎与while循环相同。 `do while loop`具有以下形式:
```cpp
do
{
// do something;
} while(expression);
```
注意:请记住使用分号';'在条件结束时。
## 有关do-while循环的详细信息
只要您确定必须至少执行一次特定进程在循环内就会使用do-while循环。它具有许多优点例如不初始化检查变量例如char addmore ='Y')等。在结束时分号是必须的。
先做一些事情然后测试我们是否必须继续。结果是do块至少运行一次。 (因为表达测试后来)。看一个例子:
```cpp
#include <iostream>
using namespace std;
int main()
{
int counter, howmuch;
cin >> howmuch;
counter = 0;
do
{
counter++;
cout << counter << '\n';
}
while ( counter < howmuch);
return 0;
}
```