The kinds of loops covered in the previous topics about loops and loops with external data all run through an entire list or for a specified number of iterations. Other than waiting for them to complete, you can't short circuit or break out of those loops.
This topic explains a different design pattern - one that allows you break out of a loop:
Update a value within the loop, then use an HTTP Request block to send the value to and retrieve it from the Postman Echo API. This enables your flow module to manipulate state across multiple iterations of the loop.
Within the loop, use an Evaluate block to increment or otherwise changes the value and a Condition block to decide whether the loop should iterate or terminate based on the new value.
The result is a kind of "while do" loop that's well-suited to pagination use cases.
Here's how the finished loop will look:
Before building the flow module, create an HTTP GET request in a collection of your choice. Configure the request with the following:
https://postman-echo.com/get?pageNumber={{value}}
pageNumber
with value {{value}}
Rename the request "Current page number".
Construct the iteration branch of the loop:
Create an HTTP Request block, choose the "Current page number" HTTP request you created above. This renames the block as Current page number.
Connect a Number block to the value
input of the Current page number block. Leave its value at 0
.
Connect an Evaluate block to the Current page number block's Success
output and rename it "Turn the page". Change value1
to "pageBeforeTurning". Insert a Select block inline and set its path to body.args.pageNumber
.
Paste the following expression into the TypeScript window:
Number(pageBeforeTurning) + 1
Connect a Delay block to the Result
output of the Turn the page block and set its value to 1500 milliseconds.
Connect a Condition block to the Delay block and rename it "Stop after page 5". Rename value1
as onPage
and paste the following expression into the Condition 1 window:
onPage > 5
This expression returns true when the page number exceeds 5. When that happens, the loop terminates. As long as the page number is less than or equal to 5, the loop keeps iterating.
Run the flow module so that output values appear for each block. In the output of the Stop after page 5 block, under default, click and drag onPage
to create a Select block that outputs the page number value.
Connect the output of the new Select block to the value
input of the Current page number block. Note that this connection loops back to the beginning, making the flow module a true loop in form, not only in function.
Add blocks to display status throughout the loop's lifecycle:
Connect a Template block to the Success
output of the Current page number block and rename it Message when iterating. Rename key
as onPage
and insert a Select block inline, change its name to "onPage" and enter body.args.pageNumber
as its path. Paste the following expression into the text window:
We are now on page {{onPage}}. Turning the page ...
Connect a Display block to the Message when iterating block. From Additional Settings, choose Text size > Large.
Connect a Template block to the Condition 1 output of the Stop after page 5 block and rename it Message when terminating. Rename key
as lastPage
and insert a Select block inline, change its name to "onPage" and choose onPage
as its path.
Paste the following expression into the text window:
Stopping! We got to page {{lastPage}}.
Connect the Display block you created earlier to the Message when terminating block.
Run the flow module. You'll see each block activate in sequence until the loop goes beyond page 5 and terminates.
Last modified: 2025/06/06