added for and foreach loop to iterate the array of names