Kotlin

Kotlin

Made by DeepSource

The range specified for iteration is empty KT-W1031

Bug risk
Major

It is important to ensure that ranges specified in for loops are valid. Ranges that are empty can lead to unexpected behavior.

Having an empty range as a loop condition can result in the loop never being executed. This can cause logical errors and prevent the intended functionality of the loop.

To fix this issue, make sure that the ranges specified in the code are valid and do not result in an empty range.

Bad Practice

for (i in 2..1) {}
for (i in 1 downTo 2) {}
val range = 2 until 2

Recommended

for (i in 1..2) {}
for (i in 5 downTo 2) {}