Replace range-based for loops to make the code more portable.