
Introducing Loops
Nothing is perfect, but this is close. When working with a list of items (e.g. a list of invoice or leads), you may need to carry out a set of actions for every item in the list.
Loops help you do that. Actions indented within a loop block will be carried out for all items in the list. It’s like saying: “For each element of this list do X, Y and Z”.
Example
In the example below we built a flow that automatically organize pictures on Box based on the recognized content. We know that the IBM Watson action “Classify an Image from URL” returns a list of values corresponding to the content of a picture. For each of these values we want to search for a folder with the same name and copy the image in it.

In this example, the IBM Watson action returns a list of classes. Since we need to search for different folders (one for each class) on Box, each Watson class must be searched one at a time on Box.
The list data pill has to be passed into the repeated step. When the input list field is selected, only list type data pills are usable in the input field, as shown below. List type pills can be identified via their stack icon, in this example classes is our list data pill.

As you can see from the app data above, the recognition results “Classes” is an array, with each line containing the content recognized and the confidence score of the recognition. If you use one of these pills from this output directly, without a repeat step for mapping, the end product will only perform the Find action on a single item of the list.
Data pills from the Loop output Data pills dropdown should be mapped to ensure that values from each list item are used when the action is repeated.
For example, if you want to ensure that you only Find Box folders for classes with recognition confidence greater than X, using pills from the Loop Data Pill drop down ensures that the Conditional step action checks the confidence value with the data from the first class on its first iteration, then with the data from the second class on its second iteration.

For example, if you want to ensure that you only Find folder Box action for classes with recognition confidence greater than X, using pills from the Loop Data Pill drop down ensures that the Conditional step action checks the confidence value with the data from the first class on its first iteration, then with the data from the second class on its second iteration.
Lastly we perform the Find Folder Box action for each one of the classes with a confidence greater than X.

Using datapills from lists
When using pills directly from a list, only the values of the first list item will be retrieved. In the following recipe, pills from the list are used directly in the Conditional step action.
In order to move through the list of classes and check the score of the confidence, the Loop step should be used to iterate through the list, and carry out the same action for each iteration.
To iterate through the classes, pass the Classes list object as input for the Loop step. The recipe will therefore iterate through the list thrice to repeat Conditional step action as many times as the classes returned by IBM Watson, with different values from different classes confidence score each time.

We’re constantly working to make our platform stronger and easier to use. If you have any question just comment this blogpost, shoot us a tweet at @stamplay or can join our Slackchannel to chat with the team and other users of our community.
Giuliano and the team,
