hw10: replaced repetitive code with loop.  D'oh!