Loop a function and store the output of each result