<!DOCTYPE qhelp PUBLIC
  "-//Semmle//qhelp//EN"
  "qhelp.dtd">
<qhelp>


<overview>
<p>This rule finds nested loops in which the iteration variable is the same for both loops. 
The behavior of the loop will be difficult to understand as the inner loop will affect the 
iteration variable of the outer loop; this is most likely a typo.</p>

<p>The rule flags the condition expression in the inner loop that uses the same variable as the iteration variable of the
outer loop. </p>

</overview>
<recommendation>
<p>If the inner loop is starting by initializing the variable to 0, it's most likely a typo and then the inner loop variable should be changed. It is good practice to use descriptive names in nested loops rather than i and j to avoid confusion. If the inner loop is merely consuming the rest of the iteration as a special case, then it's better to replace the inner for loop with a while loop and also document it.</p>

</recommendation>
<example><sample src="NestedLoopSameVar.cpp" />

</example>
<references>

<li>
  Tutorialspoint - The C++ Programming Language: <a href="http://www.tutorialspoint.com/cplusplus/cpp_nested_loops.htm">C++ nested loops</a>
</li>
<li>
  MSDN Library: <a href="http://msdn.microsoft.com/en-us/library/8y82wx12%28v=VS.80%29.aspx">Nested Control Structures</a>
</li>




</references>
</qhelp>
