Replace an iterator for loop with a foreach