use iterator method instead of loop