Switching some iterator-based for loops to use range-based for loops. No functional changes intended.