looping through an array with counter variable method