TI-Basic 89 Programming/Conditional Functions
Appearance
If
[edit | edit source]If, Control(F2):1 is a command which will determine whether or not the next line of code is executed.
Syntax: If
[edit | edit source]: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 | edit source]- 5→x
- If x=5
- Disp "True"
True
If...Then blocks
[edit | edit source]If...Then...EndIf
[edit | edit source]If...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 | edit source]: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 | edit source]- 5→x
- If x=5 Then
- 7→y
- Disp "Y is",y
- EndIf
Y is 7
If...Then...Else...EndIf
[edit | edit source]If...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 | edit source]: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 | edit source]- 8→x
- If x=5 Then
- Disp "X is five"
- Else
- Disp "X is not five"
- EndIf
X is not five
ElseIf...Then
[edit | edit source]ElseIf...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 | edit source]: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 | edit source]- 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 | edit source]- 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