Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V8026. The counter is not used...
menu mobile close menu
Additional information
toggle menu Contents

V8026. The counter is not used inside the body of the nested loop.

Jun 10 2026

The analyzer has detected a potential error of not using the loop counter in one of the loops when writing nested for loops.

The example:

func BubbleSort(values []int) {
  for i := 0; i < len(values); i++ {
    for j := 0; j < len(values) - 1; j++ {
      if values[i] > values[i + 1] {
        values[i], values[i + 1] = values[i + 1], values[i]
      }
    }
  }
}

An error occurred when implementing the bubble sort algorithm: the j counter is not used within the loop.

The fixed code:

func BubbleSort(values []int) {
  for i := 0; i < len(values); i++ {
    for j := 0; j < len(values) - 1; j++ {
      if values[i] > values[j + 1] {
        values[i], values[j + 1] = values[j + 1], values[i]
      }
    }
  }
}