Replace forEach with for loop