assuming the value stars at 1, I think I'd go with...
# random
m
assuming the value stars at 1, I think I'd go with
Copy code
generateSequence(1) { (it * 2).takeIf { it < 1000 } }.forEach { // something here }
👍 2
r
menegatti: Shouldn't that be
it < 1000
?
m
or
takeUnless
?
🧌
r
That works too
m
but you're right
just edited it
👍 1
o
thanks, that's a good a idea. i think it can be even better: for (i in generateSequence(1) { it *2 }.takeWhile { it <1000 })