use while loop, separate method