tencent cloud

Loop Node
Last updated:2025-08-18 17:18:47
Loop Node
Last updated: 2025-08-18 17:18:47

Node Function

The loop supports repeatedly executing a series of tasks until the conditions are met. Loop Node belongs to Basic Node, allowing users to cyclically execute a specific workflow by configuring input variables, loop body (workflow), and loop method.




Directions

Input Variables

Input variables take effect only within the same node and cannot be used cross-node. Support up to 50 input variables to meet scene requirements. Click "Add" to configure input variables as follows.
Configuration
Description
Variable Name
The variable name can only contain letters, digits, or underscores, must start with a letter or underscore, and is mandatory.
Description
Description of this variable. Optional.
Data source
The data source of this variable supports two options: "refer" and "input". "Refer" allows selecting output variables from all preceding nodes, while "input" supports manually filling in a fixed value.
Type
The data type of this variable cannot be selected and defaults to the variable type of "refer" or the string type of "input".
Note:
The input variables of the loop node support users manually specifying the loop array. During node runtime, the loop node iterates over the elements of the loop array. Input.Item represents the element content of the current loop array Input.

Loop Body

Represents a workflow for cyclic execution, supporting selection of workflows in "To be released" and "Released" statuses. After selecting a workflow, the page automatically displays its input variables, allowing users to set variables imported each time via the variable introduction method.
Method 1. Introduce loop array Input.Item as the input variable of the workflow
During each execution run, a new element in the array will be used as the input variable of the workflow.
Method 2. Introduce other variables (such as input variables) as the input variable of the workflow
Each run will use the same variable as the input variable of the workflow.

Loop Method

The loop node supports two loop methods: "Traverse all elements" and "Loop according to conditions". You can select the loop method based on business scenario. Among them:
Traverse all element: means traversing all elements in the loop array variable to execute the loop body. For example: if the loop array variable contains 10 articles and the loop body workflow is used to summarize the articles, then in "Traverse all element" mode, the loop node will summarize each article, finally generating 10 summary results.
Loop according to conditions: means running the loop body normally and exiting under specific circumstances. For example: if the loop array variable contains 10 articles and the loop body workflow is used to summarize the articles, the loop body will exit when the number of loops reaches 5 or an error occurs, as shown in the figure below.



Note:
The Loop variable of the Loop node is a built-in variable specific to that node, including:
Loop.Index: indicates the number of times the loop body is currently executed.
Loop.Output: indicates the output result after the current loop body execution.
Loop.ErrorCode: indicates the error status of the current loop body execution. 0 means normal, 1 indicates abnormality.
Loop.Log: indicates the log of the current loop body execution.

Output Variable

The output variable processed by this node includes the aggregated Results after loop execution (data type: array<object>), the LoopCount of loop executions, as well as runtime Error info (data type: object, this field is empty during normal operation). Manual addition by users is not supported.




Application Example

Generate an outline for each chapter based on user-provided input for topic and style, then perform paragraph writing by looping calls to the article generation workflow.



Among them, the loop body for writing articles is configured as follows:




FAQs

1. How to input text content as a loop array?
The loop body node only supports arrays of type [obj] as loop array input. You can use a code node to convert text content into a [obj] type array and import it into the loop body.
2. How to set up an infinite loop and terminate by condition?
The loop node does not support infinite loops.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback