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.
1Set @maximum = 2002Set @valueToTest = 30034If @valueToTest > @maximum Then5 Output("The value is greater than the maximum.")6EndIf
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.
1If (@age > 30 and @age <= 40) Then2 Output("Age between 31 and 40")3ElseIf (@age > 40 and @age <= 50) Then4 Output("Age between 41 and 50")5EndIf
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.
1If (@age > 30 and @age <= 40) Then2 Output("Age between 31 and 40")3ElseIf (@age > 40 and @age <= 50) Then4 Output("Age between 41 and 50")5Else6 Output("Age is either under 30 or over 51.")7EndIf