Move the expression of getting cotainer's end iterator out of loops.