while to foreach