
290 Chapter 17: Programming
17PROGRM.DOC TI-89/TI-92 Plus: Programming (English) Susan Gullord Revised: 02/23/01 1:14 PM Printed: 02/23/01 2:18 PM Page 290 of 40
The following program segment shows a For...EndFor loop (which is
discussed later in this chapter). The variable i is the loop counter. In
most cases, the variable i is used only while the program is running.
:Local i
:For i,0,5,1
: Disp i
:EndFor
:Disp i
If you declare variable i as local, it is deleted automatically when the
program stops so that it does not use up memory.
An Undefined variable error message displays when you evaluate a
user-defined function or run a user-defined program that references
a local variable that is not initialized (assigned a value).
This example is a multi-statement function, rather than a program.
Line breaks are shown here, but you would type the text in the entry
line as one continuous line, such as: Define fact(n)=Func:Local…
where the ellipsis indicates the entry line text continues off-screen.
For example:
Define fact(n)=Func:
Local m:
While n>1:
nùm!m: nì1!n:
EndWhile:
Return m:
EndFunc
In the example above, the local variable m exists independently of
any variable m that exists outside of the function.
All local variables must be assigned an initial value before they are
referenced.
Define fact(n)=Func:
Local m: 1!m:
While n>1:
nùm!m: nì1!n:
EndWhile:
Return m:
EndFunc
The TI-89 / TI-92 Plus cannot use a local variable to perform symbolic
calculations.
Using Local Variables in Functions or Programs
A local variable is a temporary variable that exists only while a
user-defined function is being evaluated or a user-defined
program is running.
Example of a Local
Variable
Tip: As often as possible,
use local variables for any
variable that is used only
within a program and does
not need to be stored after
the program stops.
What Causes an
Undefined Variable
Error Message?
You Must Initialize
Local Variables
Local variable m is not assigned an
initial value.
1 is stored as the initial value for m.
Declares variable i as local.