Suppose I have a simple loop


Now once the run is finished, I can store the data using


It works perfectly. However suppose I have a bigger loop with complicated evaluations which takes long time to complete. And I need to use the output upto i=5 before the run is complete. What I mean is that data should be stored in "dat.txt", when i=1 is complete. Then in the next line the file includes the output for i=2. This helps me to use the output file even if some problem related to computer hang problem appears and the code finishes prematurely.

Can someone enlighten me regarding the method I should use for that?

  • $\begingroup$ does not work for multiple columns, also the output format given is inside inverted comma, I can't use those further. $\endgroup$ Feb 10, 2021 at 15:29

1 Answer 1


In the Table, wrap your output in e.g. PutAppend so each time an output is generated it gets appended to a file. I recommend that you label the results with the value of the iterator as well.

Here is a minimal example, where I use Pause to simulate a long computation, and Print just to provide visual feedback to you of the progress of the computation (neither would be needed in your code):

  Print[i]; Pause[10]; {i, "results from iteration " <> ToString[i]},
 {i, 0, 5}

If you open the file in an editor such as Notepad++, you will be notified of the changes to the file and see the updates in real time.

Note that it would be up to you (or to extra code that you can write) to clear the file before each run, if you want to.


Not the answer you're looking for? Browse other questions tagged or ask your own question.