Replace array assignment with for loop