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

SR:  9.5.2#3Checked automatically with code checker

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


Description:
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.

Example:

/* 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++)
{
    ...i...(i+1)...
}
/* or, if the formula is more complex: */
for (i = 0; text[i] != \\\\\\\\0; i++)
{
    const intj = ...i...;
    ...i...j...
}