Loop counter should be outside the loop (in this case).