The last two conditions could be moved out of the for-loop as they do not depend on the iterator.