mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Tweaked #1551
To adjust example comment and Enforcement per PR #1551 comments
This commit is contained in:
parent
164c0b3b5d
commit
f92c1c2eb3
|
@ -12718,7 +12718,7 @@ consider `gsl::finally()` as a cleaner and more reliable alternative to `goto ex
|
||||||
|
|
||||||
Often, a loop that requires a `break` is a good candidate for a function (algorithm), in which case the `break` becomes a `return`.
|
Often, a loop that requires a `break` is a good candidate for a function (algorithm), in which case the `break` becomes a `return`.
|
||||||
|
|
||||||
//BAD: break inside loop
|
//Original code: break inside loop
|
||||||
void use1(){
|
void use1(){
|
||||||
std::vector<T> vec = {/* initialized with some values */};
|
std::vector<T> vec = {/* initialized with some values */};
|
||||||
T value;
|
T value;
|
||||||
|
@ -12731,7 +12731,7 @@ Often, a loop that requires a `break` is a good candidate for a function (algori
|
||||||
/* then do something with value */
|
/* then do something with value */
|
||||||
}
|
}
|
||||||
|
|
||||||
//GOOD: create a function and return inside loop
|
//BETTER: create a function and return inside loop
|
||||||
T search(const std::vector<T> &vec){
|
T search(const std::vector<T> &vec){
|
||||||
for(const T &item : vec){
|
for(const T &item : vec){
|
||||||
if(/* some condition*/) return item;
|
if(/* some condition*/) return item;
|
||||||
|
@ -12767,7 +12767,7 @@ If you really need to break out a loop, a `break` is typically better than alter
|
||||||
|
|
||||||
##### Enforcement
|
##### Enforcement
|
||||||
|
|
||||||
Flag any use of `break` and `continue` inside a loop.
|
???
|
||||||
|
|
||||||
### <a name="Res-break"></a>ES.78: Don't rely on implicit fallthrough in `switch` statements
|
### <a name="Res-break"></a>ES.78: Don't rely on implicit fallthrough in `switch` statements
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user