change while loop to for loop #115