This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Reference Guide / Mathematica Sessions  /

A.7.3 The Main Loop

All Mathematica sessions repeatedly execute the following main loop:

  • Read in input.
  • Apply $PreRead function, if defined, to the input string.
  • Print syntax warnings if necessary.
  • Apply $SyntaxHandler function if there is a syntax error.
  • Assign InString[n].
  • Apply $Pre function, if defined, to the input expression.
  • Assign In[n].
  • Evaluate expression.
  • Apply $Post function, if defined.
  • Assign Out[n], stripping off any formatting wrappers.
  • Apply $PrePrint function, if defined.
  • Assign MessageList[n] and clear $MessageList.
  • Print expression, if it is not Null.
  • Increment $Line.
  • Clear any pending aborts.

    Note that if you call Mathematica via MathLink from within an external program, then you must effectively create your own main loop, which will usually differ from the one described above.