Small question about idiomatic Kotlin :slightly_sm...
# getting-started
g
Small question about idiomatic Kotlin 🙂 Imagine the following JS code:
for (let i = 1; i <= string.length && i < MAX_LENGTH; i++)
My first attempt in Kotlin was:
for (i in 1..Math.max(string.length, maxLength))
However, this is wrong. It’s wrong because
string
is reassigned inside the loop (
substring
), and the range won’t be evaluated again.