# Save value computed in the loop and delete it

I am using For loop to calculate a value $z$ in every cycle. I would like to create a text file, save the current value $z$ in this file and afterwards delete the value from Mathematica's memory. I would also like to do it as fast as possible.

Example of my loop:

For[x=0,x<=1,x=x+0.5;z=Exp[x^2]]

• For[] and similar loops are very inefficient in Mathematica. Why don't you add what are you trying to achieve instead of focusing in the function you want to use. – Dr. belisarius Sep 22 '14 at 18:09
• See for example mathematica.stackexchange.com/a/18396/193 – Dr. belisarius Sep 22 '14 at 18:12
• do you really need to Write in the loop? It would almost certainly be faster to save the data and write it out all at once. – george2079 Sep 22 '14 at 18:33

First of all avoid using For loop better (and faster) use Do instead.
stream = OpenWrite["c:\\1.txt"];