TI-Basic 89 Programming/Conditional Functions
If
editIf, Control(F2):1 is a command which will determine whether or not the next line of code is executed.
Syntax: If
edit:If condition
- Where condition is an expression that resolves to be either true or false
- If condition is true, then the code in the next line is executed. Otherwise that code is skipped.
Ex: If
edit- 5→x
- If x=5
- Disp "True"
True
If...Then blocks
editIf...Then...EndIf
editIf...Then...EndIf, Control(F2):2:1 is a group of commands which will determine whether or not a block of code is executed.
Syntax: If...Then...EndIf
edit:If condition Then :code-block :EndIf
- Where condition is an expression that resolves to be either true or false
- If condition is true, then the code in code-block is executed. Otherwise that code is skipped
- Where code-block has one or more lines of code
Ex: If...Then...EndIf
edit- 5→x
- If x=5 Then
- 7→y
- Disp "Y is",y
- EndIf
Y is 7
If...Then...Else...EndIf
editIf...Then...Else...EndIf, Control(F2):2:2 is a group of commands which will determine which of two blocks of code is executed.
Syntax: If...Then...Else...EndIf
edit:If condition Then :code-block 1 :Else :code-block 2 :EndIf
- Where condition is an expression that resolves to be either true or false
- If condition is true, then the code in code-block 1 is executed. Otherwise it skips to code-block 2
- Where code-block 1 and code-block 2 each have one or more lines of code
Ex: If...Then...Else...EndIf
edit- 8→x
- If x=5 Then
- Disp "X is five"
- Else
- Disp "X is not five"
- EndIf
X is not five
ElseIf...Then
editElseIf...Then, Control(F2):2:3 is a command in which could be used to add more than two code blocks in If...Then...EndIf code.
Syntax: ElseIf...Then
edit:If condition 1 Then :code-block 1 :ElseIf condition 2 Then :code-block 2 :EndIf
- Where condition 1 and condition 2 are expressions that resolves to be either true or false
- If condition n is true, then the code in the respective code-block n is executed. Otherwise it skips to the next ElseIf...Then statement, to a code-block between Else and EndIf, or straight to EndIf depending on how everything is setup.
- Where code-block 1 and code-block 2 each have one or more lines of code
Ex: ElseIf...Then
edit- 8→x
- If x=5 Then
- Disp "X is five"
- ElseIf x=8 Then
- Disp "X is eight"
- EndIf
X is eight
Ex: ElseIf...Then with Else
edit- 8→x
- If x=5 Then
- Disp "X is five"
- ElseIf x=8 Then
- Disp "X is eight"
- Else
- Disp "X is neither 5 nor 8"
- EndIf
X is eight