How to create an while loop in make

Hi,

I’m trying to create a modified version of the midjourney api image generator.

Basically i want to use the repeater (if you know a better module feel free to suggest) to loop through the sleep and HTTP request until the HTTP request throws back a value of finished.

When it’s finished i want the flow to continue.

Unfortunately, at the moment the repeater still goes through each iteration.

Does someone have a suggestion on how i can do that?

It’s basically a while loop. While status processing continue checking until value = finished.

I appreciate any help.

Thanks!

Hello @KM and welcome to the Make Community!

If possible, after making your initial request, it would be better to specify a callback URL so that the service can trigger a separate scenario via webhook when it’s done doing what it’s doing.

If you search the community for “while loop” you should be able to find some other suggestions as well.

Another option is to use another helper scenario that’s capable of calling itself.
Your original scenario would end after the initial call, then use HTTP module to run the helper scenario.
After your helper scenario’s trigger module (let’s say Webhook), add the HTTP call followed by a router.
If the return is NOT finished then add a delay, then call itself via HTTP module.
if the return IS FINISHED, then proceed with the rest of your original scenario.

Hope that helps and hope it makes sense!

2 Likes

Welcome to the Make community!

This has been asked several times before.

The only method closest to a do-while loop in programming in a Make scenario is a repeater-error.

For more information, see

Short answer:

You need to throw an error to get out of the “loop”.

There are two methods if you want to do a polling wait in the same/single scenario.

Method 1 — difficulty level: Easy

The simplest solution would be to use a Sleep module to wait out 5 minutes (or the longest period that the external service takes).

You could even use more than one, if you have a Make subscription (free tier max 5 minutes per scenario run).
Screenshot_2024-01-30_090129

Method 2 — difficulty level: ???

This other method allows you to check multiple times at shorter intervals, because you “throw” an error to break from the repeater and end the scenario when successful/completed.

The secret is in the success check filter, the error handler, and the commit directive.

Hope this helps!

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

3 Likes

Hi Sam,

Thanks a lot for your help. It looks like making a while loop in make is truly not possible. Even though you suggested good workarounds it would mean that each task would take a lont time to complete. I guess i’ll just have to make a python script webhook that does it for me. It’s a bit disappointing that the simple while loop isn’t possible.
Best,
Kierin

1 Like

Well I’m sure others would agree that this is a nice feature to have.

You can submit this suggestion to the Idea exchange, under Platform ideas and improvements.

Don’t forget to search for it first, just in case someone already suggested it, so that you don’t end up creating a duplicate.
Screenshot_2024-01-17_130153

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

Here are a couple direct links to Feature Requests about this:
https://www.make.com/en/app-improvement-ideas/p/flow-control-dowhile-function
https://www.make.com/en/app-improvement-ideas/p/flow-control-while-loop-or-at-least-repeater-break

3 Likes