mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
Merged commit for PR #86 and fixed formatting
This commit is contained in:
@@ -7212,8 +7212,11 @@ This will copy each elements of `vs` into `s`. Better
|
|||||||
<a name="Res-for-init"></a>
|
<a name="Res-for-init"></a>
|
||||||
### ES.74: Prefer to declare a loop variable in the initializer part of as `for`-statement
|
### ES.74: Prefer to declare a loop variable in the initializer part of as `for`-statement
|
||||||
|
|
||||||
**Reason**: 1) By creating variables inside loops, you ensure their scope is restricted to inside the loop. It cannot be referenced nor called outside of the loop.
|
**Reason**: 1) By creating variables inside loops, you ensure their scope is restricted to inside the loop. It
|
||||||
2) some dedicated optimization can be performed more efficiently by the compiler (most importantly register allocation), since it knows that the variable cannot be used outside of the loop. For example, no need to store the result for later re-use.
|
cannot be referenced nor called outside of the loop.
|
||||||
|
2) some dedicated optimization can be performed more efficiently by the compiler (most importantly
|
||||||
|
register allocation), since it knows that the variable cannot be used outside of the loop. For
|
||||||
|
example, no need to store the result for later re-use.
|
||||||
|
|
||||||
**Example**:
|
**Example**:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user