1
$\begingroup$

For example t = 0.5; Do[t = Module[{a = t}, c = (a^2 - 2)/3;Pause[1]; err = c - a; c]; Print[err], {i, 100}] I want to see the errin every interation step while the code is running. But I don't want to see the err in my code notebook.Is there anyway to show it elsewhere? (in a new notebook or bottom border?)

$\endgroup$
1
$\begingroup$

Messages Window

You can use this printMsg function, replacing Print in your code:

printMsg[x__] := 
 NotebookWrite[
   Notebooks["Messages"][[1]],
   Cell[RawBoxes @ ToBoxes @ Row @ {x}, "Text"]
 ]

This should print to the Messages window, which you may need to open.

Window Status Area

To print to the StatusArea of the evaluation notebook use this in place of Print:

printStatus[x__] :=
  (CurrentValue[EvaluationNotebook[], WindowStatusArea] = ToString @ Row @ {x};)

Reference: How to briefly display message in status area?

Monitor

If you only want to see one value rather than a list of values you can use Monitor, though this does display within the Notebook.

x = 0;

Monitor[
 Do[x++; Pause[1], {50}],
 x
]

See also: Interrogating a running evaluation

$\endgroup$
  • $\begingroup$ Thank you Mr Wizard $\endgroup$ – xin pei Jul 25 '18 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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