This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
How to | Stop a Computation
There will be times when you want to stop Mathematica in the middle of a computation. You may have asked Mathematica to do something that you did not intend or that is taking too much time. Mathematica provides several convenient ways to stop computations, including menu items and commands that you can use in your programs.
The menu items to stop or pause computations can be accessed from the Evaluation menu:
To illustrate the stopping or pausing of computations, first set up a computation that takes some time to complete.
This Do loop sequentially prints each integer from 1 to 1000, pausing for half a second at each step. It takes over ten minutes to finish:
To stop this computation, first select its cell bracket:
Then select Abort Evaluation from the Evaluation menu:
Mathematica then outputs $Aborted:
If Abort Evaluation does not succeed in stopping the computation, you can do so by quitting the active kernel.
Select the kernel name from the EvaluationQuit Kernel menu. This menu item is located at the bottom of the Evaluation menu. Here, Local is the name of the active kernel:
This stops all computations in the selected kernel. However, by quitting the kernel you will lose the results from your session, including definitions of variables and functions and output from computations. You should therefore use this with caution.
You must have a kernel running to perform computations. If you quit your only running kernel, you must start one again. To do this, simply evaluate any expression in a notebook, or select a kernel to start in the EvaluationStart Kernel menu.
Here, kernel Local is restarted:
Mathematica lets you momentarily pause a computation instead of completely stopping it. To do this, select the cell bracket of the running computation and then select Interrupt Evaluation from the Evaluation menu:
You are then presented with a dialog box that lets you continue the evaluation, abort the evaluation, or start a kernel subsession within the interrupted evaluation:
Starting a kernel subsession lets you pause the computation and evaluate other expressions. This is very useful for checking on the status of variables in a long computation or for debugging.
Mathematica also provides an alternative to using Interrupt Evaluation to enter a kernel subsession. With a computation running, select the cell bracket of the expression you want to evaluate and then select EvaluationEvaluate in Subsession.
By selecting the brackets of more than one input cell and pressing Shift+Enter, Mathematica lets you send several cells to the kernel for evaluation.
The cells are evaluated one by one. The bracket of each cell queued for evaluation thickens, indicating it is currently being evaluated or is in the evaluation queue:
To remove a cell from this evaluation queue, first select its bracket. Here, the queued cell is selected while the Do loop continues to run:
Remove the selected cell from the evaluation queue by using Remove from Evaluation Queue from the Evaluation menu:
You can also stop a computation by using Abort as part of a Mathematica expression.
Stop the evaluation of a sequence of commands:
Click for copyable input
Define a function for doing fixed-point iteration that aborts if the value gets above a certain limit:
Click for copyable input
Here, an unstable iteration is aborted:
Click for copyable input
This is a stable iteration that approximates the golden ratio:
Click for copyable input