TI-Basic Z80 Programming/Basic Variables

What are Variables?
Variables are the meat of any programming language as they are used to store and work with data. With variables, the outcomes of programs can differ depending on the user's input or the purpose of the program. Variables in the TI calculators can store different types of data, whether it be numbers, lists of numbers, strings, mathematical functions, etc. However, each data type has its own type of variable that it can be stored in and the rules must be followed fairly strictly.

TI-BASIC is unusual among programming languages in that it does not support actual variables. Instead, all data are treated like files; there is no distinction between an ordinary number and an image, for example. TI refers to all files as "variables." Henceforth, "variable" will refer to a file usable by a program.

Types of Basic Variables
There are many types of variables, but in this chapter, only the most common ones will be dealt with. The Advanced Variables section will deal with the more complex variable types and uses. The following sections will deal with:
 * Number — numbers (e.g.,,  ,  ,  ,  )
 * List — array of numbers (e.g., )
 * String — text (e.g., )

Storing and Recalling Variables
Variables can be stored and recalled at the home screen, or within a program by simply using that variable's name. The method for recalling variables varies depending on the type of variable: To recall the value of, press  [X], then push :
 * To type a number variable, press, then the corresponding key for that letter.
 * To type a list variable, press  [LIST], then select the desired list in the list.
 * To type a string variable, press  7, then select the desired string in the list.

or to recall :

or to recall :

Numbers
Numbers are stored into variables labelled  through   and   and can be real or complex numbers (complex numbers can only be used if the calculator is in a+bi or re^&theta;i modes).

Number variables store both the integer and decimal part of a number. Examples of number variables are,  ,  ,  ,  , or. Number variables are accurate up to eight significant digits and can be in the range of  to   ($$\pm9*10^{99}$$). If an attempt is tried to evaluate or store a value outside of the range, the calculator returns an error.

The calculator can update,  ,  ,  , and   during graphing, so you may want to avoid using these variables to store non-graphing data.

Syntax
To store a number to a number variable, the syntax is as follows:

Variable
In this example, only the value of  is stored to   (i.e., changes to   will not be reflected in   after the assignment).

Equation
In this example, if,  , not the actual equation. Only the result of an equation is stored (the equation is, so  ).

Lists
Lists are essentially an array: they store an array of numbers. The individual numbers of a list are named elements. The maximum number of elements in a list is.

Syntax
To instantiate a list, the following code is used:

It is important to first instantiate a list before attempting to access it so that the size is appropriate for usage. The dim( (  [LIST] OPS 3) command stands for dimension, and in this case, we have set  as the dimension (or size) of the list.

To access a single element in a list, use the format, where N is the N-th element in the list. The index is 1-indexed, so to reference the first element in, use.

Lists can only store numbers.

Equations
In this example,  would consist of   because each element was increased by   then stored to.

Strings
Strings hold text.

Incompatible Types
It should be noted that variables can only contain their respective data type. For example, trying to store a number to a string object will result in an error.

You try it!
Try these examples to practice using the different data types.

Arithmetic
Use variables to store numbers, then perform simple operations on them. Make variables A and B equal to 3 and 7, respectively. Then output $$A/B$$, $$(AB)^A$$, and $$B+(A^{2+4B})$$.

Which outputs:

List Operation
Create a simple list using these numbers:. Now, using Disp, output each value to the screen, then output the average of the values of the list by accessing them from the list. Remember, to type a list, press <tt>2ND</tt> then a number from 1-6.

Which outputs:

String Concatenation
Set  to your first name and set   to your last name. Then, using string concatenation, print your first and last names on two lines, with preceding text  and. For example, your output would appear as follows: