converted for to foreach