We have a long Do loop for our program in which we have put a counter to see the stage of process.


  a program; counter+=counter;

But we do not want to have a cell devoted to each counter when it is printed. If this happens, we will have 10^6 cells below each other which consume a huge space in a notebook of Mathematica. Actually we wish to have a temporary printing process. Of course, the running program takes a long time to be done and we do not need Pause[nSeconds] that is emphasized in the Mathematica documents. We just want to see temporarily the counter once the program finished in every iteration! We have seen this link and this link but they do not work for us efficiently.

  • $\begingroup$ Check Monitor, or skip Print and create Dynamic @ counter before running the loop. $\endgroup$
    – Kuba
    May 31, 2017 at 6:44
  • $\begingroup$ Do you mean: Monitor[Dynamic@j, Do[j = i + 1, {i, 1, 40}]]? $\endgroup$ May 31, 2017 at 6:49
  • $\begingroup$ It just print 41!!! $\endgroup$ May 31, 2017 at 6:50
  • 1
    $\begingroup$ See also: How to create a progress bar $\endgroup$
    – Kuba
    May 31, 2017 at 6:53
  • 1
    $\begingroup$ Did you look up Monitor in the documentation? It is all explained there. Don't guess at the syntax, look it up!! $\endgroup$
    – Szabolcs
    May 31, 2017 at 7:27

2 Answers 2


Check the Documentation page for Monitor. Here is a quick example:

program := Pause[.2]
Monitor[Do[program, {i, 1, 40}], i]

Of course, the running program takes a long time to be done and we do not need Pause[nSeconds] that is emphasized in the Mathematica documents.

Pause[nSeconds] is just a stub for a program that takes significant time to compute, nothing more. Replace it with a call to your actual program!



You can use a file to decide if you want the program to print variables or not. For instance, only if the file exists, the program print variables which you are interested in.

It's tested on macOS, it should work on Linux as well.

  1. Evaluate the cell
  2. Execute the shell command whenever you want to check the status.



debugQ[] := FileExistsQ["debug.txt"]
Do[(Which[debugQ[], Print@i]; i), {i, 1, 10^8}]


echo 1 > debug.txt;rm debug.txt


enter image description here

  • $\begingroup$ Please explain what does the shell command echo 1 > debug.txt;rm debug.txt do exactly? Is it for Windows or for Linux? $\endgroup$ Jun 2, 2017 at 13:14
  • 2
    $\begingroup$ It might work on windows if you can use Bash on Windows. the shell command creates debug.txt and then delete it. During the short period of time, the program will print debug messages when the program detects that debug.txt exists. $\endgroup$
    – webcpu
    Jun 2, 2017 at 13:27
  • $\begingroup$ @UnchartedWorks Thanks, I assumed that it should be so but when run using cmd on Windows this command just creates the file "debug.txt" with contents "1 ;rm debug.txt". $\endgroup$ Jun 2, 2017 at 13:30
  • $\begingroup$ If the program takes long time to evaluate, it simply may not notice the quick creation-deletion procedure, which consequently won't have any effect. $\endgroup$ Jun 2, 2017 at 13:33
  • $\begingroup$ @AlexeyPopkov dir > debug.txt & del debug.txt $\endgroup$
    – webcpu
    Jun 2, 2017 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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