Looping based on an if statement

I want to keep querying a data source until I come up with no results. More specifically, I’m compiling all the items on a critical path, so I get one item and then search all the other items to see if the first item appears in their dependency arrays. Then I want to take all of these “secondary” items and search the rest of the items to see if the secondary items appear in their dependency arrays. I want to continue until I have all of the items that are connected via dependency, i.e., until a search of the data store does not produce any matches. This could be one iteration or possibly seven or more.

I could run a “repeat” loop for the maximum number of possible iterations, and then have a “continue” variable = true or false depending on if matches have been found. But it doesn’t seem very efficient.

What I’d like to do is have a loop that depends on an if statement. Then I could make a loop something like:

if number of results from last iteration = 0,
skip to next module,

else
run another loop and check again

end.

I have read of similar struggles and just can’t quite imagine that there isn’t an elegant solution for this that doesn’t arbitrarily use excessive calculations (like my repeating an arbitrary number of times). Someone suggested pagination, but I don’t really know how that helps (or have the first clue of how to start).

Any suggestions? Thanks very much.

Hi :wave:t5:

It is quite difficult to imagine what specific difficulties you encountered while building such a scenario without sample data and/or screenshots of what exactly is happening but I believe implementing pagination logic using “Repeater”, “Set variable” and “Get variable” modules might solve it.

I would recommend checking this topic that explains pagination basics which (slightly amended) you could implement into your scenario.
Pagination routine/logic works miracles :magic_wand:


Cheerio

2 Likes