[previous] MISRA-C:2004  Rule  13.6:  (Required) [next] Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
Loop counters shall not be modified in the body of the loop. However other loop control variables representing logical values may be modified in the loop, for example a flag to indicate that something has been completed, which is then tested in the for statement.

flag = 1;
for ( i = 0; ( i < 5 ) && ( flag == 1 ); i++ )
{
    flag = 0;   /* Compliant - allows early termination of loop */
    i = i + 3;  /* Not compliant - altering the loop counter    */
}


QAC messages that encompass this guideline:

2469 Loop control variable in this 'for' statement, %s, is modified in the body of the loop.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents