Define loop iteration variables as local in functions.
Merge pull request #243 from Alexpux/develop

Define loop iteration variables as local in functions.