TI-Basic Z80 Programming/Errors
When programming on the TI-84, the calculator will assume the written code is valid. If, as it executes the code, finds an unexpected token, or encounters an otherwise invalid statement, the TI-84 will throw an error. The calculator will stop executing the code in the program and display the type of error on the screen. There are two types of errors: syntax errors and runtime errors.
For example, consider the following example:
The syntax for the Output( command expects two integers, then a string. In this example, the second argument is a string, which the calculator does not know how to interpret. In this case, the calculator throws an error:
ERR:ARGUMENT 1:Quit 2:Goto
Code execution halts and a menu is displayed. The first option quits the program and returns to the home screen. The second option will open the code editor and scroll to the line in the code where the error occurred.
The second type of error is a runtime error. These errors can't necessarily be detected by the appearance of code. Consider the following example that displays the reciprocal of the entered value:
:Prompt A :Disp A-1
The code works fine in most scenarios:
However, consider when the user inputs
A=?0 ERR:DIVIDE BY 0 1:Quit 2:Goto
This behavior can be unwanted, since the code halts and does not continue executing if an error occurs. Therefore, it is important to consider all edge cases for calculations and statements. In this case, the line
:If A≠0 before Disp would prevent an error.
Runtime errors do not necessary have to display an error to be an error. For example, a program that is expected to display the even letters of the alphabet, but instead displays the odd letters of the alphabet, would have a runtime error since the program does not function as expected. These can be the hardest and easiest errors to fix!
You try it!
Examine the following examples, identify which kind of error is presented, and a fix to resolve the error(s).
The following program should store 10 random numbers in L1, but contains an error. Find, identify, and fix the error.
:0→dim(L1 :For(I,1,10 :rand→L1[I] :End
The error is on line 3. The given program uses square brackets ([ and ]) instead of parenthesis. The same program with the error fixed:
:0→dim(L1 :For(I,1,10 :rand→L1(I) :End
In this example, the program should output the largest number in L1 (this program assumes there is at least one value in L1).
:-9E99→L :For(A,1,dim(L1 :If L1(A)>L :A→L :End :Disp L
The error is on line 4. The given program stores the index of the largest number to L, where it should store the value itself. The fixed program:
:-9E99→L :For(A,1,dim(L1 :If L1(A)>L :L1(A)→L :End :Disp L
In the future, just use max(.