Max iterations for While server action

Could we have the option of adding a max iterations value to the while?

I can quickly think of two reasons it would be useful:

  • If you are expecting a change of data to break the loop and that doesn’t get set for some reason causing it to continue indefinitely
  • Testing (particularly 3rd party paginated API calls) without burning through a daily quota you might have

I don’t see much value of having this option to be honest. Both reasons are valid, but something that can be worked with using a simple counter variable.
In my opinion, keeping this while component as the standard while-loop in any programming language holds more value.

I would definitely like to have a BREAK step to get out of repeats and whiles. I think there is already a FR for that.

1 Like

Why not just use a variable for that?

Because you have to add a set value to initiate it, add the step to increment it and add the condition to the while expression. Several steps that could be completed by adding entering one integer in the UI that is ignored if empty/zero

Each step above also adds greater risk of typo leading to an infinite loop

1 Like

I’ve added a max option to the while loop, default it will max to Number.MAX_SAFE_INTEGER which is 9007199254740991 (9,007,199,254,740,991, or ~9 quadrillion). We could perhaps have a smaller default max but at least this will prevent it from running forever.

core.zip (2.1 KB) Unzip to lib/modules.

You have to add the extra option using the code editor until we have added it to the UI.

1 Like

This has been added to Wappler 5.3.2

2 Likes