+ 1
Kotlin: Infinite Loop
Can somebody explain to me why the code below triggers an infinite loop? Does it not just skip the 5 and then keep incrementing till 10? var i = 0 while (i < 10) { if(i == 5) { continue } i++ }
2 Réponses
+ 3
Mike because you put "continue" when i is 5, the value is forever 5 and it is always skipping the i++ part. Use a break instead or put the i++ to the top.
0
Understood. Thanks!