Branching and Looping
In Postman, we can also work on branching and looping. We can branch and loop across API requests with the help of setNextRequest() function.
This function is used to set the request to be executed next. This function takes one argument, i.e., the name of the request, which will execute next.
In the above example, "My API" is the name of the request.
Some features of setNextRequest():
Loop Over the Current Request
If you give the currently running request name in the argument of setNextRequest() function, then Postman will run the same request continuously.
But when you are continuously looping along with the same request, we have to apply some logic on setNextRequest() so that the request won't run endlessly; the collection runner will otherwise have to be force closed.
Stop Workflow Execution
To stop the execution of workflow pass the null argument in setNextRequest() function.