change while loop to for loop