0

Can anyone see why this loop isn't breaking at i[2]? Thanks.

https://code.sololearn.com/cDnA6CUnsCyw/?ref=app

26th Feb 2021, 11:41 AM
Phillipa Austin-Seymour
Phillipa Austin-Seymour - avatar
4 Respostas
+ 4
There is no element having value 2 in <myArray>, your condition `if( i == 2)` never satisfies.
26th Feb 2021, 11:49 AM
Ipang
+ 4
We can use ranged for loop for (index in 0 .. myArray.size) { if (index == 2) { break } println(myArray[index]) }
26th Feb 2021, 1:20 PM
Ipang
+ 2
Thank you so much guys!
26th Feb 2021, 2:32 PM
Phillipa Austin-Seymour
Phillipa Austin-Seymour - avatar
+ 1
Thank you so much for responding. How do I get it to break when the index == 2?
26th Feb 2021, 11:55 AM
Phillipa Austin-Seymour
Phillipa Austin-Seymour - avatar