use for loop to build index