How to get the index in a for each loop? I want to print numbers for every second iteration
For example
for (value in collection) { if (iteration_no %
It seems that what you are really looking for is filterIndexed
filterIndexed
For example:
listOf("a", "b", "c", "d") .filterIndexed { index, _ -> index % 2 != 0 } .forEach { println(it) }
Result:
b d