Replaced for loops by foreach
Merge pull request #4940 from jrbasso/2.6-router-optimization-2

Replaced for loops by foreach