Trident Help

Classic Graphing 84 manual · Chapter 22 of 25

Programming

Write, edit and run programs: the editor, the CTL and I/O command menus, loops, decisions, input and output, menus, subprograms and strings.

22.1What a program is#

A program is a list of commands that the calculator runs one after another. Use programs to repeat a calculation with new numbers, to ask questions and show results, or to automate steps you do often. A program has a name of up to 8 letters and digits, starting with a letter. Programs are saved with the calculator until you reset it.

  1. prgm NEW
  2. Name it
  3. Type the commands
  4. 2ndQUITmode
  5. prgm EXEC
  6. enter
Write and run a program
The PRGM menu on the home screen: EXEC, EDIT and NEW tabs. The display shows: [EXEC] EDIT NEW.
The PRGM menu on the home screen: EXEC, EDIT and NEW tabs.

22.2Create and run your first program#

Press prgm, move to the NEW tab with ▶ twice, and press enter on Create New. The calculator asks for a name with alpha lock already on, so just press the letter keys, then enter. The program editor opens with a colon at the start of each line. Type a command per line and press enter to start the next line. When you are done press 2ndQUITmode to leave: the program is saved automatically.

To run it, press prgm; the EXEC tab lists your programs. Press the number of the program (this types prgmNAME on the home screen) and then enter to run it. When the program ends the calculator shows Done.

Example 22.1

A program that says hello

  1. Press prgm, right, right, enter. Type the name HI: press the keys for H (the ^ key) and I (the x² key). Press enter.

    prgm▶▶enter^x²enter
    After step 1: Press prgm, right, right, enter. Type the name HI: press the keys for H (the ^ key) and I (the x² key). Press enter. The display shows: PROGRAM:HI / :.
  2. Press prgm, right (I/O), 3 to paste Disp, then type "HELLO" using the quote key and letter keys.

    prgm▶3alpha"+alphaH^alphaEsinalphaL)alphaL)alphaO7alpha"+
    After step 2: Press prgm, right (I/O), 3 to paste Disp, then type "HELLO" using the quote key and letter keys. The display shows: PROGRAM:HI / :Disp "HELLO".
  3. Press 2nd mode to leave the editor, then prgm, 1, enter to run HI.

    2ndQUITmodeprgm1enter
Result of the example "A program that says hello" The display shows: prgmHI / HELLO / Done.
You should seeprgmHI HELLO Done

22.3Edit, rename and delete programs#

Press prgm, ▶ for the EDIT tab and choose a program to open it again. In the editor ◀ and ▶ move along the line, ▲ and ▼ move between lines, del deletes a character (or an empty line), 2ndINSdel switches insert mode (press enter in insert mode to split a line) and clear empties the current line. A program's text is saved after every key.

In the editorKey
Open the command menus (CTL, I/O, EXEC)prgm
Paste any menu item or functionThe usual keys: math, 2ndLISTstat, vars, 2ndCATALOG0 and so on
New lineenter
Delete a character, or an empty linedel
Empty the current lineclear
Leave the editor2ndQUITmode

22.4The CTL menu: loops, decisions and jumps#

Inside the editor, prgm opens CTL (control) with the I/O and EXEC tabs to its right.

The CTL tab of the PRGM menu inside the program editor. The display shows: [CTL] I/O EXEC / 1:If / 2:Then / 3:Else / 4:For( / 5:While / 6:Repeat / 7↓End.
The CTL tab of the PRGM menu inside the program editor.
ItemCommandWhat it does
1IfIf the condition is true do the next command, otherwise skip it.
2ThenWith If: run all the lines up to Else or End when the condition is true.
3ElseThe lines to run when the If condition was false.
4For(For(variable, start, end, step) repeats the lines up to End, counting. The step is optional (default 1).
5WhileRepeat the lines up to End as long as the condition is true. Checks before each pass.
6RepeatRepeat the lines up to End until the condition becomes true. Always runs at least once.
7EndCloses For, While, Repeat and If-Then blocks.
8PauseStops until you press enter. Pause value shows the value first.
9LblA label, such as Lbl A, that Goto can jump to.
0GotoJump to a label.
AIS>(IS>(variable, limit): add 1 and skip the next command if now above the limit.
BDS<(DS<(variable, limit): subtract 1 and skip the next command if now below the limit.
CMenu(Menu("title","text1",label1,"text2",label2,…) shows a menu and jumps to the chosen label.
DprgmRun another program: prgmNAME.
EReturnLeave this program; a subprogram goes back to the one that called it.
FStopEnd the whole program.
GDelVarDelete a variable (back to 0), a list or a string.

22.5The I/O menu: input and output#

The I/O tab. The display shows: CTL [I/O] EXEC / 1:Input / 2:Prompt / 3:Disp / 4:DispGraph / 5:Output( / 6:getKey / 7:ClrHome.
The I/O tab.
ItemCommandWhat it does
1InputInput A asks for a value for A. Input "text",A shows your text as the prompt.
2PromptPrompt A,B asks for each variable in turn, showing A=?
3DispShows values or text, one per line: Disp A,"TEXT".
4DispGraphShows the graph screen.
5Output(Output(row,column,value) writes at a position. Rows are 1 to 8, columns 1 to 26.
6getKeyThe code of the last key pressed, or 0 for none.
7ClrHomeClears the home screen.

22.6Ask for numbers and show a result#

Example 22.2

Add two numbers

  1. Create a program ADD with the lines Prompt A,B and Disp A+B.

    prgm▶▶entermathx⁻¹x⁻¹enterprgm▶2alphaAmath,alphaBappsenterprgm▶3alphaAmath+alphaBappsenter2ndQUITmode
  2. Run it and answer 3 and 4.

    prgm1enter3enter4enter
Result of the example "Add two numbers" The display shows: prgmADD / A=?3 / B=?4 / 7 / Done.
You should seeA=?3 B=?4 7
Example 22.3

Input with your own question

  1. Create AGE: Input "AGE ",A and Disp A+1.

    prgm▶▶entermathtansinenterprgm▶1alpha"+alphaAmathalphaGtanalphaEsinalpha␣0alpha"+,alphaAmathenterprgm▶3alphaAmath+1enter2ndQUITmode
  2. Run it and type 12.

    prgm1enter12enter
Result of the example "Input with your own question" The display shows: prgmAGE / AGE 12 / 13 / Done.
You should seeAGE 12 13

22.7Repeat steps with a For loop#

For(I,1,100) runs the lines up to End once for each value of I from 1 to 100.

S=∑I=1100I=5050S=\sum_{I=1}^{100}I=5050
Example 22.4

Add the numbers 1 to 100

  1. Create SUMN: 0→S, For(I,1,100), S+I→S, End, Disp S.

    prgm▶▶enterln5÷logenter0sto→alphaSlnenterprgm4alphaIx²,1,100)enteralphaSln+alphaIx²sto→alphaSlnenterprgm7enterprgm▶3alphaSlnenter2ndQUITmode
    After step 1: Create SUMN: 0→S, For(I,1,100), S+I→S, End, Disp S.
  2. Run it.

    prgm1enter
Result of the example "Add the numbers 1 to 100" The display shows: prgmSUMN / 5050 / Done.
You should see5050

22.8Make decisions with If, Then and Else#

Example 22.5

Pass or fail

  1. Create GRADE: Prompt S; If S≥50; Then; Disp "PASS"; Else; Disp "FAIL"; End. Use 2nd math 4 for ≥.

    prgm▶▶entertan×mathx⁻¹sinenterprgm▶2alphaSlnenterprgm1alphaSln2ndTESTmath450enterprgm2enterprgm▶3alpha"+alphaP8alphaAmathalphaSlnalphaSlnalpha"+enterprgm3enterprgm▶3alpha"+alphaFcosalphaAmathalphaIx²alphaL)alpha"+enterprgm7enter2ndQUITmode
  2. Run it and answer 70.

    prgm1enter70enter
Result of the example "Pass or fail" The display shows: prgmGRADE / S=?70 / PASS / Done.
You should seeS=?70 PASS
Example 22.6

The Else branch

  1. Same program GRADE. Run it and answer 30.

    prgm▶▶entertan×mathx⁻¹sinenterprgm▶2alphaSlnenterprgm1alphaSln2ndTESTmath450enterprgm2enterprgm▶3alpha"+alphaP8alphaAmathalphaSlnalphaSlnalpha"+enterprgm3enterprgm▶3alpha"+alphaFcosalphaAmathalphaIx²alphaL)alpha"+enterprgm7enter2ndQUITmodeprgm1enter30enter
Result of the example "The Else branch" The display shows: prgmGRADE / S=?30 / FAIL / Done.
You should seeFAIL

22.9Repeat while a condition is true (While)#

Example 22.7

Double until at least 100

  1. Create DBL: 1→N, While N<100, 2N→N, End, Disp N.

    prgm▶▶enterx⁻¹apps)enter1sto→alphaNlogenterprgm5alphaNlog2ndTESTmath5100enter2alphaNlogsto→alphaNlogenterprgm7enterprgm▶3alphaNlogenter2ndQUITmode
  2. Run it.

    prgm1enter
Result of the example "Double until at least 100" The display shows: prgmDBL / 128 / Done.
You should see128

22.10Jump with Lbl and Goto#

Example 22.8

Count to 10 with a label

  1. Create CNT: 0→I, Lbl A, I+1→I, If I<10, Goto A, Disp I.

    prgm▶▶enterprgmlog4enter0sto→alphaIx²enterprgm9alphaAmathenteralphaIx²+1sto→alphaIx²enterprgm1alphaIx²2ndTESTmath510enterprgm0alphaAmathenterprgm▶3alphaIx²enter2ndQUITmode
  2. Run it.

    prgm1enter
Result of the example "Count to 10 with a label" The display shows: prgmCNT / 10 / Done.
You should see10

22.11Show a menu to the user#

Menu( takes a title, then pairs of text and label. When the user picks an option, the program jumps to that label.

Example 22.9

Pick one of two options

  1. Create PICK with Menu("PICK","ONE",A,"TWO",B), then Lbl A, Disp "GOT ONE", Stop, Lbl B, Disp "GOT TWO".

    prgm▶▶enter8x²prgm(enterprgmalphaCprgmalpha"+alphaP8alphaIx²alphaCprgmalphaK(alpha"+,alpha"+alphaO7alphaNlogalphaEsinalpha"+,alphaAmath,alpha"+alphaT4alphaW−alphaO7alpha"+,alphaBapps)enterprgm9alphaAmathenterprgm▶3alpha"+alphaGtanalphaO7alphaT4alpha␣0alphaO7alphaNlogalphaEsinalpha"+enterprgmalphaFcosenterprgm9alphaBappsenterprgm▶3alpha"+alphaGtanalphaO7alphaT4alpha␣0alphaT4alphaW−alphaO7alpha"+enter2ndQUITmode
  2. Run it. The menu appears. Press 2.

    prgm1enter
    After step 2: Run it. The menu appears. Press 2. The display shows: PICK / 1:ONE / 2:TWO.
  3. Choose option 2.

    2
Result of the example "Pick one of two options" The display shows: prgmPICK / GOT TWO / Done.
You should seeGOT TWO

22.12Place text on the screen with Output(#

Example 22.10

Write at a row and column

  1. Create POS: ClrHome and Output(2,4,"AB").

    prgm▶▶enter87lnenterprgm▶7enterprgm▶52,4,alpha"+alphaAmathalphaBappsalpha"+)enter2ndQUITmode
  2. Run it.

    prgm1enter
Result of the example "Write at a row and column" The display shows:    AB / Done.
You should seeAB Done
Example 22.11

Wait with Pause

  1. Create WAIT: Disp 1, Pause, Disp 2.

    prgm▶▶enter−mathx²4enterprgm▶31enterprgm8enterprgm▶32enter2ndQUITmode
  2. Run it. Only 1 shows. Press enter to continue.

    prgm1enterenter
Result of the example "Wait with Pause" The display shows: prgmWAIT / 1 / 2 / Done.
You should see2

22.13Call one program from another#

Inside the editor, press prgm, ▶ twice for the EXEC tab and choose a program to paste its call, prgmNAME. When the subprogram ends the calling program continues. Variables are shared between programs. Return leaves a subprogram early and Stop ends everything.

Example 22.12

A main program and a subprogram

  1. Create SUB with Disp "B".

    prgm▶▶enterln5appsenterprgm▶3alpha"+alphaBappsalpha"+enter2ndQUITmode
  2. Create MAIN: Disp "A", call prgmSUB (EXEC item 2 in alphabetical order), Disp "C".

    prgm▶▶enter÷mathx²logenterprgm▶3alpha"+alphaAmathalpha"+enterprgm▶▶2enterprgm▶3alpha"+alphaCprgmalpha"+enter2ndQUITmode
  3. Run MAIN, the first program in the list.

    prgm1enter
Result of the example "A main program and a subprogram" The display shows: prgmMAIN / A / B / C / Done.
You should seeprgmMAIN A B C

22.14Text and strings#

Text between quotes is a string. Strings can be stored in Str1 to Str0 (vars, 7) and joined with +. The CATALOG (2ndCATALOG0) also has sub( (part of a string), length(, inString( (find text), expr( (evaluate text as a calculation) and toString(.

Example 22.13

Join two strings

  1. Create JOIN: "AB"→Str1 and Disp Str1+"CD". Paste Str1 with vars, 7, 1.

    prgm▶▶enter,7x²logenteralpha"+alphaAmathalphaBappsalpha"+sto→vars71enterprgm▶3vars71+alpha"+alphaCprgmalphaDx⁻¹alpha"+enter2ndQUITmode
  2. Run it.

    prgm1enter
Result of the example "Join two strings" The display shows: prgmJOIN / ABCD / Done.
You should seeABCD

22.15Lists inside programs#

Example 22.14

Build a list of squares

  1. Create SQS: seq(X²,X,1,5)→L1 using 2nd stat, right, 5, then Disp L1.

    prgm▶▶enterln9lnenter2ndLISTstat▶5X,T,θ,nx²,X,T,θ,n,1,5)sto→2ndL11enterprgm▶32ndL11enter2ndQUITmode
  2. Run it.

    prgm1enter
Result of the example "Build a list of squares" The display shows: prgmSQS / {1 4 9 16 25} / Done.
You should see{1 4 9 16 25}

22.16Stop a running program#

Press on to break a program that is running or waiting, and the calculator shows a BREAK error with a Goto choice that opens the editor at the line. 2ndQUITmode also stops a program with the same BREAK error.

Example 22.15

Break a program

  1. Create ASK: Input A. Run it, then press on.

    prgm▶▶entermathln(enterprgm▶1alphaAmathenter2ndQUITmodeprgm1enteron
Result of the example "Break a program" The display shows: ERR:BREAK / 1:Quit / 2:Goto.
You should seeERR:BREAK

22.17Read the keyboard with getKey#

getKey gives the code of the last key pressed, or 0 if none was pressed. The code is the key's row times 10 plus its column, counting from the top-left. A common pattern waits for a key: 0→K, Repeat K, getKey→K, End.

KeyCodeKeyCodeKeyCode
◀24▲25▶26
▼34enter105clear45
0102192293
394482583
684772873
974+95−85
×75÷652nd21
alpha31y=11graph15
Example 22.16

Show the code of a key

  1. Create KEY: 0→K, Repeat K, getKey→K, End, Disp K. Use getKey from I/O item 6.

    prgm▶▶enter(sin1enter0sto→alphaK(enterprgm6alphaK(enterprgm▶6sto→alphaK(enterprgm7enterprgm▶3alphaK(enter2ndQUITmode
  2. Run it and press the 5 key.

    prgm1enter5
Result of the example "Show the code of a key" The display shows: prgmKEY / 83 / Done.
You should see83

TI-84 Plus CE is a trademark of Texas Instruments Incorporated. Trident Calculator is an independent product by South View Studios and is not affiliated with, sponsored by or endorsed by Texas Instruments. The name is used only to describe the kind of calculator this model resembles; Trident's names, keys, display, fonts and software are its own clean-room design.