Controlling the flow of a program, Using indentation, Displaying calculated results – Texas Instruments PLUS TI-89 User Manual

Page 300: Getting values into a program

Advertising
background image

Chapter 17: Programming 283

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

When you run a program, the program lines are executed in
sequential order. However, some commands alter the program flow.
For example:

¦

Control structures such as

If...EndIf

commands use a conditional

test to decide which part of a program to execute.

¦

Loops commands such as

For...EndFor

repeat a group of

commands.

For more complex programs that
use

If...EndIf

and loop structures

such as

For...EndFor

, you can make

the programs easier to read and
understand by using indentation.

:If x>5 Then
: Disp "x is > 5"
:Else
: Disp "x is < or = 5"
:EndIf

In a program, calculated results are not displayed unless you use an
output command. This is an important difference between
performing a calculation on the Home screen and in a program.

These calculations will not display
a result in a program (although they
will on the Home screen).

:12ù 6
:cos(

p/4)

:solve(x^2ì xì 2=0,x)

Output commands such as

Disp

will

display a result in a program.

:Disp 12ù 6
:Disp cos(

p/4)

:Disp solve(x^2ì xì 2=0,x)

Displaying a calculation result does
not store that result. If you need to
refer to a result later, store it to a
variable.

:cos(

p/4)! maximum

:Disp maximum

To input values into a program, you can:

¦

Require the users to store a value (with § ) to the necessary
variables before running the program. The program can then refer
to these variables.

¦

Enter the values directly into
the program itself.

:Disp 12ù 6
:cos(

p/4)! maximum

¦

Include input commands that
prompt the users to enter the
necessary values when they
run the program.

:Input "Enter a value",i
:Request "Enter an integer",n

¦

Require the users to pass one
or more values to the
program when they run it.

prog1(3,5)

Controlling the Flow
of a Program

Tip: For information, refer to
pages 295 and 297.

Using Indentation

Displaying
Calculated Results

Tip: For a list of available
output commands, refer to
page 302.

Getting Values into
a Program

Tip: For a list of available
input commands, refer to
page 301.

Advertising
This manual is related to the following products: