Education Technology

Solution 11813: Using Local Variables in Functions or Programs on the TI-89 Family, TI-92 Plus, and Voyage™ 200.

How can I use a local variable on the TI-89 family, TI-92 Plus, or Voyage 200?

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. 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.

For example, in the program segment below the variable i is a local variable:

: Local i
: For i,0,5,1
: Disp i
: EndFor
: Disp i

Please Note: The line "Local i" declares i as local. When a variable is declared as local, it is deleted automatically when the program stops so that it does not use memory.

All local variables must be assigned an initial value before they are referenced. If a user-defined function or program that references a local variable that is not initialized is evaluated or executed, the calculator will return the error message Undefined Variable. Below are two examples of functions. In the first function, the local variable is not initialized; in the second, the local variable is initialized.

Example 1:

:Define fact(n)=Func
:Local m
:While n>1
:n*m ->m
:n-1 ->n
:EndWhile
:Return m
:EndFunc

Please Note: The local variable m is not assigned an initial value.

Example 2:

:Define fact(n)=Func
:Local m
:1 -> m
:While n>1
:n*m ->m
:n-1 ->n
:EndWhile
:Return m
:EndFunc

Please Note: The value 1 is stored in the local variable m as its initial value.

Please see the TI-89 family, TI-92 family and Voyage 200 guidebooks for additional information.