Avoid unconditional jump statement

Why you should care

Having an unconditional break, return or throw in a loop renders it useless; the loop will only execute once and the loop structure itself is simply wasted keystrokes. Having an unconditional continue in a loop is itself wasted keystrokes. For these reasons, unconditional jump statements should never be used except for the final return in a function or method.
5362

How we detect

This Code Insight counts one occurrence each time one of these patterns is found into the source code:

 

return, break, continue is unconditional inside a loop.
return, throw is unconditional inside a method, unless it is the last instruction
break is unconditional in a case statement, unless it is the last instruction.

5362

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.