Do not use the same list as the in-array and the out-array in a LOOP. It won’t work.
When creating a list using more than one loop (e.g. the first loop adds several entries and the second loop adds more), do not simply make it the out-array of both loops. The second loop will overwrite the existing elements. Instead, do not specify an out-array for the second (and subsequent) loops. Create an individual entry (string or record) and use pub.list:appendToStringList or pub.list:appendToRecordList to append entries to the list.
It is sometime useful to know when you are processing the last item in a list during a loop. Before entering the loop, invoke pub.list:sizeOfList to get the size and store it in a var (e.g. “sizeVar”). Within the loop, use two sequences: one that tests for $iteration = %sizeVar% and another that is $default. The iteration sequence will execute when the last item is being processed by the loop.