Use range-based for loop.

end() was evaluated every time through a loop. This patch eliminates it.