TI-BASIC:Ans

From Learn @ Cemetech
Revision as of 02:45, 27 November 2017 by Battlesquid (talk | contribs) (code formatting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

ANS.GIF

Command Summary

Returns the last answer.

Command Syntax

Ans[→Variable]

Menu Location

While editing a program, press [2nd] then [(-)]

Calculator Compatibility

TI-83/84/+/SE

Token Size

1 byte

The Ans variable holds the last answer that was stored in the calculator. Because Ans is stored in a special storage area built-in to the calculator, and it is extensively used by the calculator, you cannot delete it. Ans is also useful; it can make your programs both smaller and faster:

  • Unlike other variables which have a value type hard-coded in (i.e., a string can only hold text, and Lists and Matrices can only hold numbers), Ans can take on whatever value you want: a real or complex, list, matrix, or string are all acceptable.
  • Along with the finance variables, Ans is faster than the real, complex, list, matrix, and string variables; and subsequently, you should try to use it as much as possible.

One of the most common places to use Ans is in place of storing a value to a variable. Just paste the Ans variable to the location where the variable was called, and then when the expression is evaluated, the calculator will use the current value of Ans. Using the Ans variable allows you to eliminate the variable, which helps save a little or a lot of memory (depending on the type of variable and its size).

30+5A→B
Disp 25A,30+5A
can be
30+5A
Disp 25A,Ans

The one major drawback to using Ans is that its current value is only temporary. Whenever you Store a value to a variable, place an expression or string on a line by itself, or use the optional argument of the Pause command, Ans is updated to the new value. This restriction essentially limits your use of Ans to only a single variable. If you are manipulating two or more variables, it's best to just use the variables.

There are several cases in which changing the value of a variable does not modify Ans, thus preserving its current value for later use:

  • storing to an equation variable
  • using the DelVar command to delete a variable (i.e., set its value to zero, if it's a real variable)
  • changing the value with [[TI-BASIC:IS>(|IS>(]] or [[TI-BASIC:DS<(|DS<(]].
  • initializing or changing the value in a For( loop.

These cases can be very useful, allowing you to use Ans to store an expression rather than create a temporary variable for it.

Timing

Storing a real value into Ans takes approximately 1.0 ms. This does not include the time needed to compute or retrieve the value, which may be significant. Accessing a real value from Ans takes approximately ?? ms.