From bfa349b64800b14acb67395ed60eb989a426ec8b Mon Sep 17 00:00:00 2001 From: peno2 Date: Thu, 13 May 2021 20:41:42 +0200 Subject: [PATCH] Remove 2 redundant else, according to rule F.56 (#1766) * Remove 2 redundant else, according to rule F.56 * Remove continue from example code Update after pull request comment. --- CppCoreGuidelines.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index ad747ff..1e22656 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -12595,10 +12595,8 @@ Readability. Error prevention. Efficiency. cout << f(v, &v[i]) << '\n'; for (gsl::index i = 0; i < v.size(); ++i) { // body messes with loop variable: can't be a range-for - if (i % 2 == 0) - continue; // skip even elements - else - cout << v[i] << '\n'; + if (i % 2 != 0) + cout << v[i] << '\n'; // output odd elements } A human or a good static analyzer might determine that there really isn't a side effect on `v` in `f(v, &v[i])` so that the loop can be rewritten. @@ -20386,7 +20384,7 @@ In particular, the single-return rule makes it harder to concentrate error check { if (x < 0) return "negative"; - else if (x > 0) + if (x > 0) return "positive"; return "zero"; }