[SalesForce] AMPScript stopping loop

Is there a break function in AMPScript? I have following code snippet and would like to end the 'For' loop if the condition is met. Currently the code will transverse the whole DE.

How can I fix this?

%%[ set @DELookup = lookuprows('DE', 'SubscriberKey', SubscriberKey) 
if rowcount(@DELookup) >= 1 then
for @i = 1 to rowcount(@DELookup) do
set @instanceRow = row(@DELookup, @i)
set @ID = field(@instanceRow, 'columnID')
if not empty(@ID)then
// DO something
]%%
%%[else]%% %%[endif]%%
%%[next @i]%% %%[else]%% %%[endif]%%
]%%

Best Answer

Here is a very simple trick to brack the For Loop -

%%[ 
SET @Data = LookUpRows('DE','SubscriberKey',@SubscriberKey)  
SET @Count = RowCount(@Data)

IF @Count > 0 Then
    For @i = 1 To @Count Do
        SET @ID = Field(Row(@Data,@i),'columnID')
            IF Not Empty(@ID) Then
                Do Somthing....
                SET @Count = @i
            EndIF
    Next @i
EndIF
]%%
Related Topic