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

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:

```cpp
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:

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