NCover should automatically ignore the "continue;" statement
NCover should automatically ignore the "continue;" statement
I use the "continue" keyword sometimes in my loops, when I want to avoid excessive block nesting. So, for example:
for (...) {
if (condition x) {}continue;}
do something;
if (condition y) {continue;}
do something else;
Assuming "condition x" and "condition y" are never satisfied under normal scenarios, the code coverage flags the "continue;" statements as not executed. However, the same code can be re-written more obtusely, like this:
for (...) {
if (!condition x) {}do something;}
if (!condition y) {do something else;}
In this case, there would be no un-executed statements...
So, can/should the "continue;" statement be safely ignored? Flagging it as not executed generally adds no information, because the equivalence to nested if statements (as in the example above) is provably universal.
Unless, we wanted code coverage analysis to not just count executable statements, but also to keep track of whether each conditional branch was evaluated both ways (as both true and false.) In my opinion, this would be going beyond mere code coverage, and somehow straying into unit/regression testing territory. But maybe that's a legitimate objective? If so, then something additional has to be done for the regular "if" statements (without an "else" clause), as well as for loop conditionals.
And while we're on the topic of branches, the "goto" statement also ought to be in the same category as the "continue" statement...