Changed loop

Changed do-while loop into a while loop.