> ## Documentation Index
> Fetch the complete documentation index at: https://learn.workflow.dog/llms.txt
> Use this file to discover all available pages before exploring further.

# Work With Lists and Loops

> Build, transform, inspect, and process collections without losing order or type information.

A List is an ordered collection of values. Lists can contain text, numbers,
objects, files, or mixed values, and they can be passed between actions as one
value.

## Create a list

Choose the source that matches how the collection is produced:

| Source                                          | Use it when                                                            |
| ----------------------------------------------- | ---------------------------------------------------------------------- |
| [Create List](/reference/actions/arrays/build)  | You have a known set of individual values.                             |
| [Create Range](/reference/actions/arrays/range) | You need a numeric sequence.                                           |
| [Append](/reference/actions/arrays/append)      | You need to add one value to an existing list.                         |
| [Join Lists](/reference/actions/arrays/join)    | You need to concatenate multiple lists.                                |
| An integration action                           | An API already returns records, messages, rows, or another collection. |

On repeatable list inputs, add and reorder individual items or switch to
providing an entire List at once. Individual inputs are best for a fixed set;
the whole-list input is best for runtime collections.

## Inspect and reshape lists

List actions transform a collection without requiring a sub-workflow:

* [Get Items by Index](/reference/actions/arrays/get-items) exposes selected
  positions as separate outputs. Index `0` is the first item, and `-1` is the
  last.
* [Slice](/reference/actions/arrays/slice) returns a contiguous section.
* [Chunk](/reference/actions/arrays/chunk) splits a list into smaller lists.
* [Flatten](/reference/actions/arrays/flatten) removes nested list levels.
* [Unique](/reference/actions/arrays/unique) removes repeated values.
* [Sort](/reference/actions/arrays/sort) reorders the items.
* [Length](/reference/actions/arrays/length) returns the item count.

Use these focused actions before reaching for a loop. They make the workflow
easier to read and avoid starting a child workflow for work a single action can
perform.

## Process every item

[Loop Workflow](/reference/actions/core/loop-workflow) runs a callable workflow
once for each item in **Payloads**.

<Steps>
  <Step title="Build the item workflow">
    Give the child workflow the [Sub-Workflow
    trigger](/reference/triggers/core/callable). Read the current item with
    [Data from Trigger](/reference/actions/core/trigger-data).
  </Step>

  <Step title="Return one result">
    Connect the transformed value to [Return
    Data](/reference/actions/core/return-data).
  </Step>

  <Step title="Configure the loop">
    In the parent workflow, select the child in **Loop Workflow** and connect
    the source list to **Payloads**.
  </Step>

  <Step title="Use the results">
    **Results** contains one child result for each input item, in the same
    order.
  </Step>
</Steps>

Iterations run sequentially. This preserves ordering and avoids overlapping
child runs, but the total runtime grows with both the number of items and the
duration of each child workflow.

<Note>
  A child that finishes without **Return Data** contributes `null` at its
  position. If a child run fails, the loop action fails instead of returning a
  partial results list.
</Note>

Loop Workflow accepts up to 1,000 payloads. Split larger collections into
batches before invoking it.

## Filter with a predicate workflow

[Filter With Workflow](/reference/actions/arrays/filter-with-workflow) runs a
callable workflow for each item and keeps the original items whose returned
value is truthy.

The predicate workflow should:

1. Read the item from **Data In**.
2. Compare or validate it.
3. Return the decision through **Return Data**.

The output keeps matching items in their original order. The returned decision
does not need to be a Boolean, but an explicit Boolean makes the predicate's
intent clearer.

For example, filter a list of orders with a **Needs review?** predicate, then
send the matching orders to a **Create review task** loop workflow.

Like Loop Workflow, filtering is sequential, accepts at most 1,000 payloads,
and fails if any child run fails.

## Find the first match

[Find With Workflow](/reference/actions/arrays/find-with-workflow) tests items
from the beginning and returns the first original item whose predicate result
is truthy. It stops testing after a match and returns `null` when none match.

Use it instead of filtering when:

* only one item is needed;
* list order defines priority; or
* avoiding unnecessary child runs matters.

## Preserve the difference between an item and a result

The three workflow-backed list actions return different things:

| Action                   | Output                                                |
| ------------------------ | ----------------------------------------------------- |
| **Loop Workflow**        | The value returned by the child for every item.       |
| **Filter With Workflow** | The original items whose child result is truthy.      |
| **Find With Workflow**   | The first original item whose child result is truthy. |

If you need both an original item and derived fields, have the loop child
return an object containing both. [Create Object](/reference/actions/objects/build)
can assemble a predictable result such as:

```json theme={null}
{
  "source": {
    "id": "order_123",
    "total": 249
  },
  "requires_review": true,
  "reason": "Order total exceeds threshold"
}
```

## Choose a list strategy

<AccordionGroup>
  <Accordion title="I only need a built-in list transformation">
    Use a dedicated Arrays action. It runs in the current workflow and
    communicates the operation directly.
  </Accordion>

  <Accordion title="I need to run several actions for each item">
    Use **Loop Workflow** and put the per-item sequence in a callable child
    workflow.
  </Accordion>

  <Accordion title="I need all items that pass a custom test">
    Use **Filter With Workflow** with a predicate child workflow.
  </Accordion>

  <Accordion title="I need only the first item that passes">
    Use **Find With Workflow**. Put the highest-priority candidates first.
  </Accordion>
</AccordionGroup>

<Warning>
  External side effects completed by earlier iterations are not rolled back if a
  later child fails. Design loop children so they can be retried safely when
  they create records, send messages, or modify remote state.
</Warning>
