Nested forEach, How to distinguish between inner and outer loop parameters?

Viewed 20674

In Kotlin, if you want to use the element of the forEach, you can use the it keyword. So now I wonder that what should I do if I have a forEach inside forEach like that:

list.forEach {
    val parent = it
    it.forEach {
        // `it` now become the element of the parent.
    }
}

I think that defines a new variable only for the naming convention be so stupid. Have any other solution for this problem?

2 Answers
Related