shorted solution to use a while loop