# TI-Basic 89 Programming/Conditional Functions

## IfEdit

If, Control(F2):1, is a command which will determine whether or not the next line of code is executed.

### Syntax: IfEdit

```: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.

```:5→x
:If x=5
:Disp "True"
```
```True
```

## If...Then blocksEdit

### If...Then...EndIfEdit

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...EndIfEdit

```: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

```:5→x
:If x=5 Then
:7→y
:Disp "Y is",y
:EndIf
```
```Y is
7
```

### If...Then...Else...EndIfEdit

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...EndIfEdit

```: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...EndIfEdit

```:8→x
:If x=5 Then
:Disp "X is five"
:Else
:Disp "X is not five"
:EndIf
```
```X is not five
```

### ElseIf...ThenEdit

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...ThenEdit

```: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...ThenEdit

```: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 ElseEdit

```:8→x
:If x=5 Then
:Disp "X is five"
:ElseIf x=8 Then
:Disp "X is eight"
:Else
:Disp "X is neither 5 or 8"
:EndIf
```
```X is eight
```