loops through arrays which length varies