kotlin foreach last index in loop code example Example: for loop in kotlin with index collection.forEachIndexed { index, element -> // ... }