TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
TIOBE - C Coding Standard

SR:  9.5.2#3Checked automatically with code checker

Synopsis:A control variable shall not be altered by the body of a for statement.
Severity Level:3


Modifying a control variable is a very confusing practice - bugs can easily be introduced when the code is enhanced later on in the software cycle. If one control variable depends directly on another, it is clearer to make this dependency explicit.

/* confusing: */
for (i = 0; text[i] != '\0'; i++)
    ...(i++)...(i--)...  /* assuming left to right evaluation */
/* make the dependency clear: */
for (i = 0; text[i] != '\0'; i++)
/* or, if the formula is more complex: */
for (i = 0; text[i] != '\0'; i++)
    const int j = ...i...;