This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / The Mathematica Book / Mathematica Reference Guide / Mathematica Sessions /

A.7.3 The Main Loop

All Mathematica sessions repeatedly execute the following main loop:

FilledSmallSquare Read in input.

FilledSmallSquare Apply $PreRead function, if defined, to the input string.

FilledSmallSquare Print syntax warnings if necessary.

FilledSmallSquare Apply $SyntaxHandler function if there is a syntax error.

FilledSmallSquare Assign InString[n].

FilledSmallSquare Apply $Pre function, if defined, to the input expression.

FilledSmallSquare Assign In[n].

FilledSmallSquare Evaluate expression.

FilledSmallSquare Apply $Post function, if defined.

FilledSmallSquare Assign Out[n], stripping off any formatting wrappers.

FilledSmallSquare Apply $PrePrint function, if defined.

FilledSmallSquare Assign MessageList[n] and clear $MessageList.

FilledSmallSquare Print expression, if it is not Null.

FilledSmallSquare Increment $Line.

FilledSmallSquare 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.