C++核心準(zhǔn)則ES.75: 避免使用do語句

ES.75: Avoid?do-statements
ES.75: 避免使用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.
可讀性,避免錯誤。中止條件位于循環(huán)的最后(可能被忽視的位置),并且第一次進入循環(huán)時不會檢查循環(huán)條件
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語句的清晰易懂的例子,但同時也存在很多錯誤。
Enforcement(實施建議)
Flag?do-statements.
標(biāo)記使用do語句的代碼。
原文鏈接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es75-avoid-do-statements
覺得本文有幫助?請分享給更多人。
關(guān)注微信公眾號【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>
評論
圖片
表情
