1
$\begingroup$

Imagine I want to track the progress of constructing a complex Table or Do object by temporarily printing the iteration number. For example, if I do

Table[PrintTemporary[i];, {i, 20}]

I get

enter image description here

which is almost what I want, but I would rather have each print vanish at each step and get replaced by the following one so that I don't produce this huge list. Any ideas?

$\endgroup$
1
  • 2
    $\begingroup$ Monitor[Table[Pause[0.1], {i, 0, 1, 1/100}], ProgressIndicator[i]] or Monitor[Table[Pause[0.1], {i, 0, 100}], i] $\endgroup$
    – Roman
    Mar 30, 2022 at 14:39

1 Answer 1

8
$\begingroup$
Monitor[Table[Pause[0.1], {i, 0, 100}], i]
$\endgroup$
2
  • $\begingroup$ I've been using PrintTemporary[Dynamic[i]];Table[Pause[0.1], {i, 0, 100}] but this is nicer. $\endgroup$
    – Chris K
    Mar 30, 2022 at 16:14
  • $\begingroup$ @ChrisK I think it's pretty much the same, but Monitor is more integrated and a bit more careful with localizing the variables. Maybe someone who knows more about variable scoping can give more information on this point. $\endgroup$
    – Roman
    Mar 30, 2022 at 17:08

Your Answer

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

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