converting for(x:xs) to foreach(x in xs)