change the while loop to for loop