E0052

E0052#

Warning name: unused_loop_variable

A loop variable is not updated in loop.

When a loop variable is not updated, this could be a potential bug that you have forgotten to update it, leading to an infinite loop.

Erroneous example#

///|
pub fn f() -> Unit {
  for i = 0, radix = 10; i < 10; {
    println(i.to_string(radix~))
  }
}

Suggestion#

There are multiple ways to fix this warning:

  • If this variable is indeed constant during the loop, you can remove it from the initialization and make it constant

  • If your code depends on change of the variable, you should update it somewhere in the loop.

///|
pub fn f() -> Unit {
  let radix = 10
  for i = 0; i < 10; i = i + 1 {
    println(i.to_string(radix~))
  }
}