690 Programming
Note: Displaying a result with or does not store that result. If you
expect to refer later to a result, store it to a global variable.
Using local variables
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
The following program segment shows a For...EndFor loop (which is
discussed later in this module). The variable i is the loop counter. In most
cases, the variable i is used only while the program is running.
À Declares variable i as local.
Note: When possible, declare as local any variable that is used only
within the program and does not need to be available after the program
stops.
What causes an undefined variable error message?
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).
For example:
À Local variable m is not assigned an initial value.
©
(p/4)&maximum
maximum
©
Local i À
For i,0,5,1
Disp i
EndFor
Disp i
Define fact(n)=Func
Local m
À
While n>1
n
¦m&m: n–1&n
EndWhile
Return m
EndFunc