mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
Add braces to for loop in P.1 example
`for` with no `block-statement` as its `statement` is bad practice and should not be shown in an example. This example is meant to demonstrate code duplication and expessiveness, not to show poor usage of braces or lack thereof.
This commit is contained in:
@@ -486,11 +486,12 @@ The second version leaves the reader guessing and opens more possibilities for u
|
|||||||
cin >> val;
|
cin >> val;
|
||||||
// ...
|
// ...
|
||||||
int index = -1; // bad
|
int index = -1; // bad
|
||||||
for (int i = 0; i < v.size(); ++i)
|
for (int i = 0; i < v.size(); ++i) {
|
||||||
if (v[i] == val) {
|
if (v[i] == val) {
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user