Reduce the scope of for loops iterator variables