This is a simple guide to programming in TI-Basic. Many high school math courses require a graphing calculator, and being able to write programs can be an essential skill, both in terms of doing math and having something to do during class.
(Note: this article was written with the TI-83/84 (including Plus/Silver Edition) graphing calculators in mind, although most versions of TI-Basic are essentially the same)
Congratulations on getting a graphing calculator! Learning to program on it can lead to endless opportunities for creating games, flying through repetitive math and physics homework, and most importantly having fun! This guide is intended to accommodate people who are new to programming, but of course anyone who already has programming experience can understand it too.
First off, you can create a new program by pressing PRGM and going to the NEW tab. You can run and edit programs from the EXEC and EDIT tabs, respectively.
One very useful app for programming in TI-Basic is CtlgHelp (Catalog Help). It should have come pre-installed on your calculator, but in any case you can download it from this site. To use it, it must first be started from the apps menu. Then, whenever you are unsure about how to use a particular command, just find that command in a menu (or from 2nd>CTLG, which is a huge list of all the commands) and press the + button to see more information about it.
Formatting & Legends used in this guide:
In this guide, commands will be represented as follows: always include the bold words as they are, replace the italicized parts with something else, and the parts enclosed by [brackets] are sometimes used, depending on the situation. //These are just comments, don’t put them into your code!//
Shortcut keys will be shown as 1stkeypress>nextkeypress>nextkeypress>etc.
Colons are used to separate commands. Every new line (from pressing enter) automatically starts with a colon, but you can also put multiple commands on the same line by inserting colons between them. If you have a long program, you can scroll through it faster with alpha-lock (2nd>ALPHA) on.
Here we go!
Types of Variables
There are several types of variables in TI-Basic. You should start off with the simple ones (single numbers and strings) before moving on to lists and matrices.
String: A string is a string of text characters. There are 10 pre-named strings available for use; they can be accessed from VARS>7. Whenever working with strings, be sure to use “quotation marks”.
Single number: These are represented by letters A-Z and theta (θ).
List: Go to 2nd>LIST to access the list menu. Lists are lists of numbers, and the Nth element of list MYLIST is expressed as ∟MYLIST(N). In this form, you can use list elements just as if they were letter variables. Creating a new list is easy: Under the list menu, go to the OPS tab, then scroll down to the small ∟ and put it in. Then use the command length->dim(∟MYLIST) to tell the calculator how many numbers you want your list to hold.
Matrix: A two-dimensional list. The matrix menu is under 2nd>MATRX. Unlike lists, matrices can’t be named. Instead, you have to use one of the 10 pre-named ones [A] through [J]. Since this happens to be a simple guide, we can skip this concept for now.
The STORE command is used to store to variables. The STO> button is above ON
The value of the expression is stored to the variable. An expression is anything that has a numerical value (with the exception of strings). For example, 69->G; H+2->H; “HELLO WORLD”->Str1; √(A²+B²)->C, etc.
There are several ways to ask for user input, the most straightforward of which is the Input command. It can be found at PRGM>I/O tab>1 and is used as follows:
This results in the “instructions” being displayed on the screen (if provided), and after the user types something and presses enter, their input is stored to the variable. You can input both numbers and strings.
Of course, a program that doesn’t give any output is useless! The easiest way to display something is by using the Disp command, which is accessed from PRGM>I/O tab>3 (by the way I/O is short for input/output):
isp variable or “text”
which simply displays whatever it is given (text must have “quotes”). To display to a specific part of the screen, use the Output command.
:Output(y,x,variable or “text”)
Output is from PRGM>I/O tab>6
For some reason, the standard coordinate system is reversed in TI-Basic. Instead of the standard (x,y), it uses (y,x). The calculator’s output screen is 8 lines tall and 16 columns wide, with 1,1 on the top left and 8,16 on the bottom right. So to output “HELLO WORLD” in the center of the screen, you would type
The math commands can be found by pressing MATH (surprise!). Since they are relatively self-explanatory, I would recommend using CtlgHelp (along with some trial & error) to find out how they are used. TI-Basic has tons of math commands because it’s designed for use on a calculator.
Now try creating a formula program that asks for one or more input variables, evaluates a formula using the variables, and outputs an answer. See how much easier math and physics homework is already? (Hint: It might even work on tests too…)
Conditions are statements that can be checked and turn out to be true or false. For example, you can check for A=1; B≥C; and things like that. The conditional operators are found at 2nd>TEST.
Under the LOGIC tab (found by the same shortcut) is stuff that you can use to combine conditional statements. And & or are self-explanatory, “not” reverses the outcome of the conditional (true turns into false and vice-versa), xor is the same as “or” except that it becomes false if both statements are true.
For example, (A>B and A≤B) is always false, but (A>B xor A≤B) is always true.
Control structures are among the most important commands in all programming languages. They control the flow of the program by making decisions.
Don’t forget the guide’s format! (alwaysputinthis changethis [usethissometimes])
:If condition [:Then] //I usually put If and Then on the same line, separated by a colon//
:do this stuff if the condition is true
[:or else do this stuff if the condition is false]
If is found at PRGM>1; Then is at PRGM>2; Else is at PRGM>3; End is at PRGM>7
Only put in Then and End if a) you have more than one command to execute if the condition is true, or b) if you want to use “Else”. For example, if you wanted to increase X by 1 only if X was less than 10, you would type
:If X<10 :X+1->X
which I also find easier to read than if they were on two separate lines.
However, if you also wanted to decrease X by 1 if the condition wasn’t true (i.e. X≥10), you would type
:If X<10 :Then :X+1->X
:Else :X-1->X :End
So all this does is move X one step closer to 10. (Or if X=10, it decreases X by 1)
:do this stuff while the condition is true
While is found at PRGM>5
Same as “If”, except that the commands that are sandwiched between While and End are executed over and over again as long as the condition is true. (It would have the same effect as putting an infinite number of identical “If” blocks one after another) Repeat is just the opposite of While, for example While not(X>5) is the same as Repeat X>5. I like to think of Repeat as “Repeat until”.
:For(variable,starting value,ending value)
:do this stuff once for each value of the variable from the starting to ending values
For is found at PRGM>4
This is a loop (just like “while”) with a built-in counter. For example, to add the numbers from 1 to 100 you would type:
:0->S //Make sure the sum starts at 0 before we start adding anything!//
This is equivalent to S+1+2+3+…+100->S, except that the variable A replaces all the values from 1 to 100, one by one! Of course, using the For( loop is also much easier and more flexible.
Goto is found at PRGM>0; Lbl is at PRGM>9
Jumps to the place in the program that is identified by Lbl lblname. When possible, we usually try to use loops instead of Lbl/Goto, but Goto can be very useful, especially for beginning programmers. One reason for this is that loops are structured logically, compared to the haphazard jumping of Goto.
which is found way down in the PRGM menu.
This stops a program immediately. Programs automatically stop at the end of their code, so this is only necessary if you want to stop in the middle.
By combining these tools with a few of the MATH commands on your calculator (Hint: there’s a remainder function!), it would be a valuable programming exercise to make a prime factorization program which asks the user to input a number, tests to see if that number is divisible by a bunch of smaller numbers, and outputs the prime factorization of the number. Don’t get discouraged if your program doesn’t work at first; debugging a frustrating but natural element of programming. Have fun with it and try making a friendly UI
I’m going to stop here, having covered the most important commands that you need in TI-Basic. If this article is popular enough, I might make another one for the more advanced features of TI-Basic, leading into game creation. Until then, thanks for reading and have fun derping around on your calculator!