change for to while loop