Functions are interpreted, or ‘called’ either within an AMPscript block or inline AMPscript, at the location where they appear on the page or in the message. However, functions don’t need to be contained in the same AMPscript block. For example, when using conditional statements, the conditional expression can span multiple blocks:
%%[ var @balance set @balance = Lookup('Points Balance', 'Balance', 'MemberId', _subscriberKey) ]%% %%[ if @balance < 100 then ]%% You are a valued bronze member. %%[ elseif @balance > 100 and @balance < 500 then ]%% You are a valued silver member. %%[ else ]%% You are a valued gold member. %%[ endif ]%%
In the same way, Process Loops can (and typically do) span multiple blocks, as indicated below.
<h2>Your Order Items</h2> <ul> %%[ var @orderId, @rows, @row, @rowCount, @i set @orderId = AttributeValue("OrderId") set @rows = LookupRows("Orders","OrderId", @orderId) set @rowCount = rowcount(@rows) if @rowCount > 0 then for @i = 1 to @rowCount do var @name, @value set @row = row(@rows, @i) set @name = field(@row,"Name") set @value = field(@row,"Value") ]%% <li>%%=v(@name)=%%, $%%=v(@value)=%%</li> %%[ next @i ]%% %%[ else ]%% <li>No items ordered</li> %%[ endif ]%% </ul>