Improving loops using the iterator