Convert more loops to range-based equivalents