updated program to be a while loop