
296     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 296 of 40
To execute one group of commands if a conditional test is true and a
different group if the condition is false, use this structure:
:If x>5 Then
:  Disp "x is greater than 5"
:  2ùx!x
:Else
:  Disp "x is less than or
   equal to 5"
:  5ùx!x
:EndIf
:Disp x
A more complex form of the If command lets you test a series of
conditions. Suppose your program prompts the user for a number
that corresponds to one of four options. To test for each option
(If Choice=1, If Choice = 2, etc.), use the If...Then...ElseIf...EndIf
structure.
Refer to Appendix A for more information and an example.
You can also control the flow of your program by using Lbl (label)
and Goto commands.
Use the Lbl command to label (assign a name to) a particular
location in the program.
Lbl  labelName
You can then use the Goto command at any point in the program to
branch to the location that corresponds to the specified label.
Goto  labelName
Because a Goto command is unconditional (it always branches to the
specified label), it is often used with an If command so that you can
specify a conditional test. For example:
:If x>5
:  Goto GT5
:Disp x
:--------
:--------
:Lbl GT5
:Disp "The number was > 5”
If...Then...Else...
EndIf Structures
If...Then...ElseIf...
EndIf Structures
Lbl and Goto
Commands
name to assign to this location (use the same
naming convention as a variable name)
specifies which Lbl command to branch to
Executed only if x>5.
Executed only if x5.
Displays value of:
• 2x if x>5.
• 5x if x5.
If x>5, branches directly to
label GT5.
For this example, the program
must include commands (such
as Stop) that prevent Lbl GT5
from being executed if x5.