TI-Basic 84 Programming/Control Flow Statements

If edit

If, PRGM:CTL:1 is a command that, when it's condition is true, will execute the next line of code. If the condition happens to be false, then the program will skip to the second line of code after the statement.

Syntax: If edit

:If condition
  • Where condition either an (in)equality (X=3, A>B), or an expression (5+2X), which resolves to be either true (non-zero) or false (zero).


Ex: If edit

PROGRAM:TEMP
5→X
If X>3
Disp "X IS MORE THAN 3"
Disp "END OF PROGRAM"
prgmTEMP
X IS MORE THAN 3
END OF PROGRAM


Else edit

Else, PRGM:CTL:3 is a command that, when a previous If statement is not met, will execute the next line of code. If the condition happens to be false, then the program will skip to the second line of code after the statement.

Syntax: Else edit

:If condition
:Then
://some action
:Else
://some other action
  • Else executes when the condition in the If statement is not met.

Ex: Else edit

PROGRAM:TEMP
5→X
If X>3
Then
Disp "X IS MORE THAN 3"
Else
Disp "X IS LESS THAN OR EQUAL TO 3"
Disp "END OF PROGRAM"
prgmTEMP
X IS MORE THAN 3
END OF PROGRAM


Then edit

Then, PRGM:CTL:2 is a command used to have a conditional statement (If or Then) execute a block of code as opposed to a single statement.

Syntax: Then edit

:If condition
:Then
://some code
://some more code
:End
  • Code block is started with a Then statement and ended with the End, PRGM:CTL:7


Previous: Input
Next: Test Conditions and Logical Operators
Table of Contents: TI-Basic 84 Programming