Movatterモバイル変換


[0]ホーム

URL:


Create a list-based loop with the For block

You can build a flow that loops over a list. For example, you can run a flow that loops over a list of email addresses and emails each person in the list.

This tutorial’s goal is to teach you how to set up and use list-based loops. To achieve this goal, you’ll build a flow that iterates over the first three letters of the alphabet.

Create a new flow

You build flows in a workspace. Workspaces let you organize your API projects and collaborate with your team.

To create a new flow, do the following:

  1. Choose an existing workspace orcreate a new one.
  2. In the upper left corner, clickNew >Flow iconFlow.

Add For and Collect blocks

With theFor block, you can build a loop that iterates over a list. For example, if you want to run a loop that loops over a list of the alphabet, you connect theFor block to such a list.

In the next procedure, you’ll use theList block to define this list.

To add aFor block, do the following:

  1. From the canvas toolbar, clickAdd iconBlock.
  2. SelectFor. If you want to search for the block, enter “for” in the search.
  3. Click the location on the canvas where you want to place theFor block.
  4. ACollect block automatically appears on the canvas.

Connect a List block

When you connect two blocks, you connect one block’s input to another block’s output. Inputs are on the block’s left side and outputs are on its right side.

In this tutorial, you’ll use theList block to define the list you want your loop to iterate over.

To connect aList block, do the following:

  1. Hover over theFor block’sList input port. The pointer changes to a crosshair.

    Hover over the List input port
  2. Decide where on the canvas you want to place theList block and drag the port to that location.

  3. SelectList iconList. If you want to search for the block, enter “list” in search.

  4. ClickAdd iconAdd data blocks and selectString iconString. If you want to search for the block, enter “string” in the search.

  5. Enter the string’s value. For example, if you want to iterate over the first three letters of the alphabet, enter “a”.

  6. Repeat the previous two steps until you complete your list.

You can loop over any list. For example, you can get a list from anHTTP Request block’s response or use theEvaluate block to generate a list.

As an alternative, replace theList block with anEvaluate block, switch to TypeScript (upper-right corner), and add the following code to the code editor:

const alphabet=[]for(let i=0; i<26; i++){alphabet.push(String.fromCharCode(97+ i))}alphabet

This code creates an empty list, adds the letter “a” to it, and loops over the code until it adds all 26 letters of the alphabet to the list.

Connect to the Collect block

TheCollect block saves multiple outputs to a list. In this tutorial, your loop will run three times, output three values, and use this block to save these values to a list.

To connect theCollect block, do the following:

  1. Hover over theFor block’s output port. The pointer changes to a crosshair.
  2. Drag theFor block’s output port to theCollect block’s input port.

Connect a Display block

TheDisplay block displays incoming data, such as theCollect block’s outgoing list.

To connect aDisplay block, do the following:

  1. Hover over theCollect block’sList output port. The pointer changes to a crosshair.
  2. Decide where on the canvas you want to place theDisplay block and drag the port to that location.
  3. SelectOutput iconDisplay. If you want to search for the block, enter “display” in search.

Run the flow

From the canvas toolbar, clickRun iconRun.

Create a list-based loop flow

Congratulations! You created a list-based loop and displayed the result in aDisplay block.

Last modified: 2025/11/17



[8]ページ先頭

©2009-2025 Movatter.jp