SalesforceSalesforce Marketing Cloud SpecialistMarketing Cloud DeveloperEasy
How do IF/ELSEIF/ELSE/ENDIF work in AMPscript? Provide an example.
Suggested answer
AMPscript uses IF condition THEN ... ELSEIF condition THEN ... ELSE ... ENDIF for conditional logic. Conditions use comparison operators (==, !=, >, <) and logical operators (AND, OR, NOT). Example:
%%[
SET @tier = Lookup("Loyalty","Tier","Email",emailaddr)
IF @tier == "Gold" THEN
SET @msg = "Thank you, Gold member!"
ELSEIF @tier == "Silver" THEN
SET @msg = "Thank you, Silver member!"
ELSE
SET @msg = "Thank you for being a member!"
ENDIF
]%%
%%=@msg=%%
ENDIF is mandatory to close every IF block. Nested IFs are supported but can hurt readability.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.