mirror of
https://github.com/github/codeql.git
synced 2026-01-18 17:04:50 +01:00
It was a Visual Basic reference anyway, and it doesn't seem to provide more information than the link we have already.
34 lines
1.2 KiB
XML
34 lines
1.2 KiB
XML
<!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>
|
|
|
|
|
|
|
|
|
|
</references>
|
|
</qhelp>
|