adds an index with a loop