rangeTo is not intuitive at all

Well, I suppose these things are a matter of taste but I do like Kotlin’s for statement and do find it intuitive.

When I see downTo I know straightaway that the loop’s going downwards without having to figure out whether the start-point is greater than the end-point. And, given it’s going downwards, it’s logical that any step should be positive.

Similarly, when I see until I know that the range excludes the end-point and, if it’s just .. then it includes the end-point.

Also, in the latest coding conventions, it actually recommends that you use for rather than forEach in many cases.

So, thankfully, I don’t see the humble for loop being removed from the language any time soon.

1 Like