Replaces a manually incremented index variable in a for loop with the use of a withIndex() function.