change print for loop to foreach