Specifically, it is not clear what you mean by “store all output,” or what loops and arrays have to do with anything. Does “store all output” mean “save the everything that appears in the REPL to a file,” like Matlab’s “diary on”? If not that, what?
To get help your question needs to be clear enough for people to understand what you’re talking about. An example of some code and what you want stored from it would be ideal.