Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Possible Duplicates:
Intermediate display similar to PrintTemporary
Estimating progress on plots
How to create a progress bar?
How to determine how much of a table is generated?

I'm trying to print an output from every iteration of a Do[] loop, but without it continuing down the notebook. I want the Print[] output to be overwritten in the same cell with the new value. Here is a MWE of what I'm trying, but I can't seem to get the expected behavior.

Do[
  If[i==1,
    Print["Output = ", Dynamic[i]]
  ]
,{i,10}
]

So in other words, on the first iteration, I want to see "Output = 1", and then every subsequent iteration I want to see the 1 change to a 2, 3, 4, etc. in the same cell.

share|improve this question
1  
One idea is to use PrintTemporary. –  PlatoManiac Sep 5 '12 at 13:32
    
@PlatoManiac Post an answer! –  belisarius Sep 5 '12 at 13:44
1  
@Verde I am so so incorrigibly lazy! Thx for motivating... –  PlatoManiac Sep 5 '12 at 13:49
1  
Some more related near duplicates (if others want to choose alternatives): mathematica.stackexchange.com/q/5985/5, mathematica.stackexchange.com/q/5978/5, mathematica.stackexchange.com/q/1489/5 –  rm -rf Sep 5 '12 at 18:10
add comment

marked as duplicate by rm -rf, Sjoerd C. de Vries Sep 5 '12 at 22:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

You could use Monitor like :

Monitor[Do[Pause[3], {i, 1, 10^3}], i]
share|improve this answer
add comment

Here is one way,

Print["Output = ", Dynamic[j]];
Do[j = i; Pause[0.1];, {i, 10}]
share|improve this answer
add comment

There are many, many possibilities to achieve something like that. If you want to use Dynamic, you could set a global value which you observe

Dynamic[globalWatch]

Do[
 If[OddQ[i], globalWatch = i];
 Pause[.1];
 ComplicatedCalculation[i],
 {i, 100}
 ]

I always suspect, whether Do is really needed, but sometimes when I for instance iterate over a list of files I want to process, I use it too. In such a situation, I use PrintTemporary as suggested by PlatoManiac to see the progress. PrintTemporary is nice because you can print all information you like and no matter it fills the screen, it gets erased after the computation is done.

share|improve this answer
add comment

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