Having trouble with while loop