Overview of entering a function, Why create a user-defined function, Differences between functions and programs – Texas Instruments PLUS TI-89 User Manual

Page 302

Advertising
background image

Chapter 17: Programming 285

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 285 of 40

Functions (as well as programs) are ideal for repetitive calculations
or tasks. You only need to write the function once. Then you can
reuse it as many times as necessary. Functions, however, have some
advantages over programs.

¦

You can create functions that expand on the

TI

-89 / TI-92 Plus

’s

built-in functions. You can then use the new functions the same
as any other function.

¦

Functions return values that can be graphed or entered in a table;
programs cannot.

¦

You can use a function (but not a program) within an expression.
For example:

3

ù

func1(3)

is valid, but not

3

ù

prog1(3).

¦

Because you pass arguments to a function, you can write generic
functions that are not tied to specific variable names.

This guidebook sometimes uses the word command as a generic
reference to instructions and functions. When writing a function,
however, you must differentiate between instructions and functions.

A user-defined function:

¦

Can use the following instructions only. Any others are invalid.

Cycle

Define

Exit

For...EndFor

Goto

If...EndIf (all forms)

Lbl

Local

Loop...EndLoop

Return

While...EndWhile

!

(

§

key

)

¦

Can use all built-in

TI

-89 / TI-92 Plus

functions except:

setFold

setGraph

setMode

setTable

switch

¦

Can refer to any variable; however, it can store a value to a local
variable only.

The arguments used to pass values to a function are treated as
local variables automatically. If you store to any other
variables, you must declare them as local from within the
function.

¦

Cannot call a program as a subroutine, but it can call another
user-defined function.

¦

Cannot define a program.

¦

Cannot define a global function, but it can define a local function.

Overview of Entering a Function

A function created in the Program Editor is very similar to the
functions and instructions that you typically use from the Home
screen.

Why Create a User-
Defined Function?

Note: You can create a
function from the Home
screen (see Chapter 5), but
the Program Editor is more
convenient for complex,
multi-line functions.

Differences
Between Functions
and Programs

Tip: For information about
local variables, refer to
pages 288 and 290.

Advertising
This manual is related to the following products: