Fix bug introduced in commit 3c945c

Refactoring of foreach -> for loop retained counter increment.