The break;
statement, as its name indicates, breaks the control flow of the program in an unstructured way.
It reduces the program readability, and makes refactoring more complex when used outside of switch
.
The following code:
int i = 0; while (true) { if (i == 10) { break; // Non-Compliant } Console.WriteLine(i); i++; }
should be refactored into:
int i = 0; while (i != 10) // Compliant { Console.WriteLine(i); i++; }
The following code is compliant:
int foo = 0; switch (foo) { case 0: Console.WriteLine("foo = 0"); break; // Compliant }