Creating a Loop in WhatsApp

Cesar Banchio Updated by Cesar Banchio

We cannot have closed loops on a bot, but we can use the jump to block to bypass this. We will create a simple flow to show this.

The flow is divided in 2 parts, the loop and the rest of the bot. On this scenario, we will use the iteration variable to set the amount of times we want to loop, and will be used in a conditions block to decide if the loop should continue or not.

The first jump to block will be set to send the user to the message block "Welcome to the loop"

A closer look to the loop part of the flow:

At the beginning of the flow, we will use a formula block to subtract 1 to the iteration variable (very important, otherwise, we will be on an infinite loop), and then we will check at the end of the flow if this variable equals to 0. If so, the loop ends and we can go on with the flow.

The formula inside the formula block is:

Subtract(@iteration, 1)

If it doesn't equal to 0, we will use a jump to block to send the user to the formula block:

How did we do?

How to calculate the number of days between two selected dates (WhatsApp)

AI in WhatsApp

Contact