< TI-Basic 89 Programming
If
If, Control(F2):1 is a command which will determine whether or not the next line of code is executed.
Syntax: If
: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
:5→x :If x=5 :Disp "True"
True
If...Then blocks
If...Then...EndIf
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
: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
:5→x :If x=5 Then :7→y :Disp "Y is",y :EndIf
Y is 7
If...Then...Else...EndIf
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
: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
:8→x :If x=5 Then :Disp "X is five" :Else :Disp "X is not five" :EndIf
X is not five
ElseIf...Then
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
: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
: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
: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
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.