C++中避免使用do语句的原因是什么

这篇文章将为大家详细讲解有关C++中避免使用do语句的原因是什么,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

Reason(原因)

Readability, avoidance of errors. The termination condition is at the end (where it can be overlooked) and the condition is not checked the first time through.

可读性,避免错误。中止条件位于循环的最后(可能被忽视的位置),并且第一次进入循环时不会检查循环条件

Example(示例)

int x;
do {
   cin >> x;
   // ...
} while (x < 0);
Note(注意)

Yes, there are genuine examples where a do-statement is a clear statement of a solution, but also many bugs.

确实存在使用do语句的清晰易懂的例子,但同时也存在很多错误。

关于C++中避免使用do语句的原因是什么就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。