Homework using iterator