Iterator (for loop) action

Loop through a list

The "Iterator (for loop)" Action in no-code Workflows allows you to loop through an array of items and do something with every item in the list.

For example, let's say you want to let users type in cities they would like to visit and display those cities on a map.

However, APIs like Mapbox and Google Maps expect longitude and latitude coordinates. It can't locate the city with a simple name.

In that case, to display the cities on the Map element in WeWeb, you would need to loop through the list of cities typed in by the user and get the coordinates from another API.

Here's one way you could do it 👇

Iterator workflow example

In the example above, you can see that:

  1. we loop through a list of city names
  2. based on the current item we are looping through, we make a dynamic API call to OpenCage to get the coordinates of the city
  3. we update a selectedCityMarkers variable that we will then bind to our map element to display markers on the selected cities

Stop a loop (pass through)

In some cases, you may want to stop an interation inside the loop when it doesn't meet a condition.

In the example below, we are looping through a guests list of people we invited but we only want guests who said they'd attend our event to be added to the confirmedGuests list, otherwise, we want to move on to the next guest in our list, i.e. the next iteration in our loop.

We do this by creating a pass through condition that stops the iteration when the condition is not met. In this case, when the rsvp value is not yes:

A pass through condition inside a for loop

To add a pass through condition in a WeWeb Workflow, simply click on a little + icon:

Adding a pass through condition to a WeWeb workflow

Last Updated:
Contributors: Joyce Kettering