mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08: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:
parent
6907911089
commit
7763b97b52
@ -486,11 +486,12 @@ The second version leaves the reader guessing and opens more possibilities for u
|
||||
cin >> val;
|
||||
// ...
|
||||
int index = -1; // bad
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
for (int i = 0; i < v.size(); ++i) {
|
||||
if (v[i] == val) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// ...
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user