Exercise 8, added logic for buidling the while loop