Fix bug redeclare index var in inner loop.