A do-while node works like the do-while statement in programming languages: it runs an inner workflow in a loop and evaluates an exit condition at the end of each iteration. The loop runs at least once before the condition is checked. Use a do-while node alone, or combine it with an assignment node to iterate over a result set.
Prerequisites
Before you begin, ensure that you have:
A DataWorks Standard Edition workspace or higher — do-while nodes are not available in Basic Edition. See Differences among DataWorks editions for details
Read Composition and workflow orchestration of a do-while node to understand how to configure the inner workflow
Read Built-in variables to understand the variables available inside the loop
Read Sample code for the end node for reference exit condition implementations
Read Precautions to understand how to test a do-while node and view its run logs
Limitations
| Constraint | Detail |
|---|---|
| Edition | DataWorks Standard Edition and higher only |
| Maximum loops | 1,024 iterations per node instance |
| Parallel execution | Not supported — each loop starts only after the previous one ends |
How it works
A do-while node has three built-in components:
| Component | Role | Can be deleted? |
|---|---|---|
| Start node | Marks the beginning of each iteration; does not run business logic | No |
| Shell node | Sample business processing node provided by DataWorks; can be replaced with another node type | No (replace with another node type as needed) |
| End node | Evaluates the exit condition; returns True to continue or False to stop | No |
Execution follows this sequence in each iteration:
The start node signals the beginning of the loop.
Inner nodes run in dependency order.
The end node evaluates the exit condition.
If the end node returns
True, the next iteration starts. If it returnsFalse, the loop ends.
Built-in variables available to all inner nodes:
| Variable | Description | Starting value |
|---|---|---|
${dag.loopTimes} | The current iteration count | 1 |
${dag.offset} | The offset of the current iteration count from 1 | 0 |
Inner nodes reference input and output parameters configured on the do-while node using ${dag.<parameter name>}.
Create a do-while node
Go to the DataStudio page. Log on to the DataWorks console. In the top navigation bar, select the desired region. In the left-side navigation pane, choose Data Development and Governance > Data Development. On the page that appears, select the desired workspace from the drop-down list and click Go to Data Development.
Create the node. Hover over the
icon and choose Create Node > General > do-while. Alternatively, find the target workflow in the left pane, click the workflow name, right-click General, and choose Create Node > do-while.In the Create Node dialog box, set the Name and Path parameters, then click Confirm.
Example: loop five times and print the iteration count
This example runs a do-while node for exactly five iterations. In each iteration, the shell node prints the current loop number.
What's next
To pass data between the outer workflow and inner nodes, configure input and output parameters on the do-while node. Inner nodes reference them using
${dag.<parameter name>}.To iterate over a result set, combine the do-while node with an assignment node. Use
${dag.offset}(starts from 0) to index into each row.The do-while node always runs at least one iteration before evaluating the exit condition, matching the behavior of a do-while statement. It does not support a pre-check like a while loop. To achieve for-each behavior, use
${dag.offset}and configure input/output parameters accordingly.