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.
This commit is contained in:
peno2
2021-05-13 20:41:42 +02:00
committed by GitHub
parent 211f6cfe3a
commit bfa349b648

View File

@@ -12595,10 +12595,8 @@ Readability. Error prevention. Efficiency.
cout << f(v, &v[i]) << '\n'; 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 for (gsl::index i = 0; i < v.size(); ++i) { // body messes with loop variable: can't be a range-for
if (i % 2 == 0) if (i % 2 != 0)
continue; // skip even elements cout << v[i] << '\n'; // output odd elements
else
cout << v[i] << '\n';
} }
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. 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) if (x < 0)
return "negative"; return "negative";
else if (x > 0) if (x > 0)
return "positive"; return "positive";
return "zero"; return "zero";
} }