MISRAC2004-13.6
In this section:
Synopsis
(Required) Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
Enabled by default
Yes
Severity/Certainty
Low/High

Full description
A for loop counter variable was found that is modified in the body of the loop. This check is identical to MISRAC++2008-6-5-3.
Coding standards
- MISRA C:2004 13.6
(Required) Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
- MISRA C++ 2008 6-5-3
(Required) The loop-counter shall not be modified within condition or statement.
Code examples
The following code example fails the check and will give a warning:
int main(void) {
int i;
/* i is incremented inside the loop body */
for (i = 0; i < 10; i++) {
i = i + 1;
}
return 0;
}
The following code example passes the check and will not give a warning about this issue:
int main(void) {
int i;
int x = 0;
for (i = 0; i < 10; i++) {
x = i + 1;
}
return 0;
}