The analyzer has detected that an outer loop counter is used as an inner loop counter, which can lead to program malfunction.
The example:
let i = 0, j = 0;
for (i = 0; i < 5; i++) {
for (i = 0; i < 5; i++) { // <=
matrix[i][j] = ....;
}
}
The code fills a 5x5 matrix. However, due to a typo, the same variable is used as the loop counter in both the outer and inner loops. As a result, after the inner loop completes, the i variable becomes 5, causing the outer loop to terminate early, and only the first matrix column is filled.
The fixed code:
let i = 0, j = 0;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
matrix[i][j] = ....;
}
}
This diagnostic rule is classified as:
Was this page helpful?