change a list traversal to use a for loop