Why not multi for?


#1

Hi all,

Minor question.

It might be good to have a shortcut for:

for (i in 1..10)
         for (j in 1..10)
             blah(i,j)

as:

for (i in 1..10, j in 1..10)
     blah(i,j)

#2

I’m not sure I like this. The key thing here is that i and j don’t loop independently, rather that j is looped inside the i loop (for a total of 100 iterations). This syntax hides that and certainly doesn’t help learnability (for beginners, not experienced developers in other languages). If you really want to

for (i in 1..10) for (j in 1..10)
    blah(i,j)

Is valid Kotlin, It’s ugly though.


#3

Yes, I am actually thought about something like list comprehensions (like in Erlang or Haskell).