Converts a for loop to a forEach function call.