前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则ES.75: 避免使用do语句

C++核心准则ES.75: 避免使用do语句

作者头像
面向对象思考
发布2020-06-03 11:04:53
2720
发布2020-06-03 11:04:53
举报

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.

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

Example(示例)

代码语言:javascript
复制
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.

标记使用do语句的代码。

原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es75-avoid-do-statements

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-06-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ES.75: Avoid do-statements
  • Reason(原因)
    • Note(注意)
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档