Download User's Guide

Transcript
ForLoopVarAssign.rule
Items Enforced
ForLoopVarAssign.rule
Don't assign to loop control variables
in the body of a for loop
This rule checks whether you assign to loop control variables in the body
of a for loop.
Reason for rule: For loop control variables should only be modified in
the initialization and condition expressions of the for loop statement.
Modifying them inside the body of the for loop makes the loop condition
difficult to understand and points to a possible logical flaw in the code.
Example
void func() {
for (int i = 0; i < 100; i++) {
// Violation
i += 3;
}
for (int i = 0; i < 100; i++) {
i++;
}
}
256
// Violation