update for loop function