### 2.8.3 Previous outputs

The ans command returns the outputs of the previous commands.

- ans takes one optional argument:

  Optionally, n, an integer (the 0-based index of the command, by default n=−1).

- ans(⟨ n⟩) returns the corresponding result; in particular, ans(-1) returns the previous result.

#### Example

If the first command that you enter is:

2+5

7 |  |  |  |  |  |  |  |  |  |

then later references to ans(0) will evaluate to 7.

Note that the argument to ans does not correspond to the line number in Xcas. For one thing, the line numbers begin at 1. What’s more, if you go back and re-evaluate a previous line, then that will become part of the commands that ans keeps track of.

If you give ans a negative number, then it counts backwards from the current input. To get the latest output, for example, you can use ans(-1). With no argument, ans() will also return the latest output.

Similarly, the quest command returns the previous inputs. Since these will often be simplified to be the same as the output, quest(n) sometimes has the same value as ans(n).

You can also use Ctrl plus the arrow keys to scroll through previous inputs. With the cursor on the command line, Ctrl+Up will go backwards in the list of previous commands and display them on the current line, and Ctrl+Down will go forwards.