Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V7038. The loop condition may be...
menu mobile close menu
Additional information
toggle menu Contents

V7038. The loop condition may be incorrect. The condition and update expression of the loop use different variables.

Aug 05 2026

The analyzer has detected a for loop whose counter is not updated in the loop update expression. Instead, a different variable is updated. This looks like a typo that may result in an infinite loop or incorrect termination.

The example:

function findFirst(arr, len, predicate) {
  for (let i = 0; i < Math.min(len, arr.length); ++len) {
    if (predicate(arr[i]))
      return i;
  }
  return -1;
}

The function should find the first element index in an array of the len length that satisfies the predicate. However, in the loop update expression, the len variable is incremented instead of i. If predicate(arr[0]) is false, the loop will repeatedly check the first element.

The fixed code:

function findFirst(arr, len, predicate) {
  for (let i = 0; i < Math.min(len, arr.length); ++i) {
    if (predicate(arr[i]))
      return i;
  }
  return -1;
}

This diagnostic rule is classified as: