-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:None
-
Message:Refactor the code to remove this break statement.
-
Default Severity:Minor
-
Impact:Low
-
Likelihood:Low
-
Covered Languages:C#, C, C++, Objective-C
-
Irrelevant for Languages:VB.Net
-
Remediation Function:Constant/Issue
-
Constant Cost:10min
-
Analysis Scope:Main Sources, Test Sources
break; is an unstructured control flow statement which makes code harder to read.
Ideally, every loop should have a single termination condition.
Noncompliant Code Example
for (element = list.first; element != null; element = element->next) { // First termination condition if (!matches(element->value)) { // Second termination condition break; // Noncompliant } /* ... */ }
Compliant Solution
// Compliant for (element = list.first; element != null && matches(element->value); element = element->next) { /* ... */ }
- is implemented by
-
CPP-378 Rule: break statements should not be used except for switch cases
-
- Closed
-
-
CPP-707 Create Objective-C rules repository containing targeted rules
-
- Closed
-
- is related to
-
RSPEC-3385 "Exit" statements should not be used
- Active
-
RSPEC-924 Loops should not have more than one "break" or "goto" statement
- Active
1.
|
C# | RSPEC-3322 |
|
Active | Unassigned |