Am I right to say that the syntax to iterate from ...
# getting-started
j
Am I right to say that the syntax to iterate from first (inclusive) to last (exclusive) is
for (i in first..last - 1)
or
for i in first.until(last))
? Isn’t there a shorter syntax? In my experience, most ranges are not closed at the end. For example, it’s common to iterate from a given index in a list or string to list.size/string.length. The canonical loop in Java is
for (int i = 0; i < max; i++)
, whereas the canonical one in Kotlin seems to be
for (i in 0..max)
, but those two don’t do the same thing. I find it unintuitive.