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.

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.

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.

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.