Challenge: For Loops | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/7910496-programming-in-kotlin-fundamentals/lessons/22

I think you solved the 1st challenge incorrectly and showcased a common mistake in programming. Especially in ranges and indexes… The ever popular “Off By One”. Your range includes and printed 21 integers because 10…30 includes both ends.

The third challenge showcases the same :slight_smile:

Hey @foolsrapier! :]

It’s not a mistake in this case. I was showcasing the use of ranges, and as such I wanted to print all of the numbers.

In some of the later challenges/episodes, I explained the difference between .. and to, and open/closed ranges.

But you’re right, it depends on what you want to achieve. In this case, I just wanted to print all of the numbers in the range.

I didn’t showcase an i-based for loop from 0 to n-1. If I wanted to do that, I’d mention how to avoid the last number! :]

Thanks!