Why does While action not behave like Repeat?

Server side question: Why does the While action not behave like Repeat?

I understand, a repeat iterates through an array, and While executes the steps until the expression evaluates to false. All good there.

My question relates to Scope of variables and output.

In a repeat, it has its own local scope…setting values within a repeat are local to that repeat, unless we use the global option. And the output from within the repeat is retained for each iteration, by placing the output within the array of the repeat.

However, in the while action, the output only displays the last values set.

Is this by design? If so, why? And can we have a while action that behaves like a repeat in terms of scope and output?

An example:

While:
Screen Shot 2020-10-15 at 1.01.12 PM

While results:
Screen Shot 2020-10-15 at 1.00.35 PM

Repeat:
Screen Shot 2020-10-15 at 12.59.34 PM

Repeat results:

1 Like

@patrick Any thoughts on this?

There were some technical limitation with the while loop that we could not achieve to have an inner scope. Also there is no data that is being iterated in the while loop that needs to be accessed from inside the loop. Because of this difference the output also differs, the steps in the repeat loop are having its own scope and outputs its data in that scope while the while loop doesn’t create such a sub-scope.

I believe the limitation was with the javascript promise based actions, the client-side actions in the flow component in which we can’t use the new async and await syntax for browser compatibility.

Thanks for the explanation.

So there is no way to accomplish the following (retrieving a paged api) with a while action?

Screen Shot 2020-10-19 at 8.35.06 AM

Couldn’t you not just use repeat with the number of total pages.

Sure, I could do the first api action, then repeat, with a 2nd api action within the repeat…but that is why we have While loops, right?

What is the use case of a while loop, if we don’t have access to the local scope within it?

It looks like you are doing this in Server Connect, which server model (NodeJS, PHP) do you use?

I could perhaps show you how to create a custom module/action for it.

I use both models, but no need for you to dive into this further although I appreciate the offer! I was just making sure I wasn’t doing something wrong (or there was a bug) in trying to make the While action work. I can easily get around this.