Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V787. Wrong variable is probably...
menu mobile close menu
Additional information
toggle menu Contents

V787. Wrong variable is probably used in the for operator as an index.

Apr 25 2017

The analyzer detected a loop counter used as an index in the loop termination condition. Such code looks suspicious.

Consider the following example:

for (int i = 0; i < n; ++i)
  for (int j = 0; j < arr[j]; ++j)
    ....

The programmer must have intended to use the variable 'i' instead of 'j':

for (int i = 0; i < n; ++i)
  for (int j = 0; j < arr[i]; ++j)
    ....