[SalesForce] Increment AmpScript for loop by more than 1

Is there a way to increment an AmpScript for loop by more than 1, for example by 2? (Please excuse the logic within the for loop – it is just a quick example).

SET @RowCount = 21

IF @RowCount > 10 THEN
  FOR @i = 10 to @RowCount DO
    SET @Value = FIELD(ROW(@foo, @i)), "Value")
  NEXT @i
  /*NEXT SET @i = ADD(@i, 2), would this work?*/
ENDIF

Basically I am trying to make ampscript act like this for loop:

for(int i = 10; i <= RowCount; i +=  2){
  //do stuff
}

Best Answer

Don't think you can reassign @i, but you can use the AMPScript mod() function to take action on every other row:

%%[
SET @RowCount = 10

FOR @i = 1 to @RowCount DO

  if mod(@i,2) == 0 then
    outputline(concat("<br>i: ",@i))
  endif

NEXT @i
]%%

Output

i: 2 
i: 4 
i: 6 
i: 8 
i: 10 
Related Topic