Back to Intellij Community

ReplaceManualRangeWithIndicesCalls

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/ReplaceManualRangeWithIndicesCalls.html

2025.3-rc-2541 B
Original Source

Reports until and rangeTo operators that can be replaced with Collection.indices or iteration over collection inside for loop.

Using syntactic sugar makes your code simpler.

The quick-fix replaces the manual range with the corresponding construction.

Example:

fun main(args: Array<String>) {
      for (index in 0..args.size - 1) {
          println(args[index])
      }
  }

After the quick-fix is applied:

fun main(args: Array<String>) {
      for (element in args) {
          println(element)
      }
  }