ELI5: Nested for-loops

ELI5: Nested for-loops

Hi guys, I’m currently learning Kotlin, it’s my first programming language – so I’m totally new to this.

Everything so far has made sense, and I’ve managed to figure it out, but this for-loop is driving me crazy!

fun main() {

for (i in 1..3) {

for (j in 1..i) {

print(j)

}

}

}

From the IDE, I know the print output is: 112123, but I cannot figure out why!

1..i should be 1, and i is 1..3 which is 123, so shouldn’t the output be 1231 or 1123?

Can someone please ELI5 this for me!

submitted by /u/omglikevasever
[link] [comments]