new SFMC user here. I'm just wondering if there's an equivalent of a javascript (or GTL) switch statement within AMPscript or if I'm restricted to using IF ELSE statements.

For example, If I take the example of GTL's switch, I would LOVE to do something like this in AMPscript:

    var @value, @outcome
    set @value = RequestParameter('entered-value')

      when @value =="Banana"
        set @outcome = "Yellow"
      when @value == "Apple" 
        set @outcome = "Red"
      when @value == "Pear"
        set @outcome = "Green"
    end switch

Otherwise, is it possible to combine GTL with AMPscript to achieve this.

Thank you!

1 Answer 1


No, there's no case/switch syntax in AMPScript. You would need to use IF/ELSEIF/ENDIF statements to achieve the same result:

    var @value, @outcome
    set @value = RequestParameter('entered-value')

    IF @value == "Banana" THEN
        SET @outcome = "Yellow"
    ELSEIF @value == "Apple" THEN
        SET @outcome = "Red"
    ELSEIF @value == "Pear" THEN
        SET @outcome = "Green"
  • Thought so, thanks Macca.
    – marly
    May 8, 2020 at 4:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .