# If Statements

Use the `If` statement to perform conditional processing. At a minimum, an `If` statement must include:

- The keyword `If` immediately preceding the condition that you want to evalute.
- The keyword `Then` immediately following the condition.
- The keyword `EndIf` to close the block.

These keywords aren’t case-sensitive; that is, `IF`, `If`, and `if` all function in the same way.

This example shows a minimal `If` statement.

```
Set @maximum = 200
Set @valueToTest = 300

If @valueToTest > @maximum Then
  Output("The value is greater than the maximum.")
EndIf
```

Evaluations in `If` statements can include any of these input types:

- Constants
- Variables
- Attributes and data extension values
- Function calls

In the example, the condition is met, so the function outputs `The value is greater than the maximum.`

## ElseIf Statements

Use the `ElseIf` statement to test additional conditions. You can include multiple `ElseIf` statements in an `If` block.

This example outputs one string of text if the value of the `@age` variable is 31–40, and a different string if it’s 41–50.

```
If (@age > 30 and @age <= 40) Then
  Output("Age between 31 and 40")
ElseIf (@age > 40 and @age <= 50) Then
  Output("Age between 41 and 50")
EndIf
```

## Else Statements

Use `Else` statements to catch any condition that isn’t specifically handled by the conditions in the `If` or `ElseIf` statements. You can only include one `Else` statement in an `If` block.

This example outputs one string of text if the value of the `@age` variable is 31–40, a different string if it’s 41–50, and a third string for all other values.

```
If (@age > 30 and @age <= 40) Then
  Output("Age between 31 and 40")
ElseIf (@age > 40 and @age <= 50) Then
  Output("Age between 41 and 50")
Else
  Output("Age is either under 30 or over 51.")
EndIf
```

## See Also

- [Evaluating Conditions in AMPscript](/docs/marketing/marketing-cloud-ampscript/guide/mc-ampscript-guide-language-basics-condition-evaluation.md)
