节点 / builtin / flow
Loop
Execute a set of actions repeatedly based on conditions
此内容尚不支持你的语言。
Repeat a group of steps while your conditions hold, up to a safety limit.
What it does
Section titled “What it does”Loop has two inputs and two outputs:
- Input (top): where the data first comes in.
- Loop Back (bottom input): connect the last step of the repeated part here.
- Loop (output): the steps to repeat start here.
- Done (output): the workflow continues here once the loop ends.
Each time data reaches the node, it checks the Conditions. While they hold, it sends the data out of Loop; your steps run and come back through Loop Back, and the check runs again. As soon as the conditions fail, or the pass count reaches Max Iterations, the data leaves through Done.
Every pass sends { done, currentIndex, inData }, where currentIndex counts the passes from 1 and inData is the data that arrived. Use {{ $input.currentIndex }} in the repeated steps, for example as a page number.
When to use it
Section titled “When to use it”- Page through an API until it returns no more results.
- Retry a step until it reports success.
- Repeat an action a set number of times.
To work through a long list a few items at a time, Split in Batches is simpler. Most nodes already run once per item, so you rarely need Loop just to handle every item of a list.
Inputs and settings
Section titled “Inputs and settings”| 设置项 | 类型 | 作用 |
|---|---|---|
| Max Iterations | Number | Maximum number of loop iterations. 默认值:100 |
| Conditions (必填) | Conditions | The conditions to evaluate. |
Max Iterations accepts 1 to 1,000. The limit stops a loop whose conditions never fail from freezing the tab.
Outputs
Section titled “Outputs”-
Done -
Loop
Each output item has these fields:
| Field | 类型 | What it holds |
|---|---|---|
| done | True/false | True when the loop exits through Done |
| currentIndex | Number | |
| inData | Any | The incoming data, unchanged |
{ "done": true, "currentIndex": 0, "inData": null}When the loop exits through Done, its pass counter resets, so a loop nested inside another loop starts again from 1 on the next outer pass.
Dependencies and credentials
Section titled “Dependencies and credentials”None. This node needs no connection and has no slots for other nodes.
Example workflow
Section titled “Example workflow”Fetch every page of a paginated API:
- A Set Variable node sets
hasMoretotrue. - Loop with the condition
{{ $run.hasMore }}(Boolean) is true, Max Iterations 50. - From Loop: Http Request to
https://api.example.com/items?page={{ $input.currentIndex }}, then Set Variable stores the response’shasMoreflag. Connect it back to Loop Back. - From Done: continue with the collected data.
Common issues
Section titled “Common issues”- The loop stops after one pass. The conditions were false on the second check. Make sure the repeated steps update the value the condition reads, and that the last step is connected to Loop Back, not to the top input.
- The loop always runs exactly Max Iterations times. The conditions never become false. Check the field and operator, or raise the limit if the work really needs more passes.
- Nothing runs after the loop. Connect the next steps to Done, not to Loop.
Related nodes
Section titled “Related nodes”- Split in Batches: work through a list a batch at a time.
- IF: the same kind of conditions, without repeating.
- Poll Until: call a URL repeatedly until the response says it is done.
- Wait: pause between passes.