exercise 5 - used a while loop instead of each do