> This page is for Postman Flows, version Latest (v12) (default).
> For other versions, use one of these documentation indexes:
> - Latest (v12) (default): https://learning.postman.com/flows/latest-v-12/llms.txt
> - v11: https://learning.postman.com/flows/v11/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt.

# Create a count-based loop with the Repeat block

You can build a flow that loops over a count. For example, you can run a flow that loops over a count of three and generates a list of three random numbers.

This tutorial's goal is to teach you how to set up and use count-based loops. To achieve this goal, you'll build a flow that uses a loop to count to three.

## Create a new flow

To create a new flow, do the following:

1. Choose an existing workspace or [create a new one](/docs/collaborating-in-postman/using-workspaces/create-workspaces/).
2. Click ![Add icon](https://assets.postman.com/postman-docs/aether-icons/v12/action-add-stroke.svg#icon) in the left sidebar and select ![Flow icon](https://assets.postman.com/postman-docs/aether-icons/v12/icon-entity-flow-stroke.svg#icon) **Flow**.

When a flow is created, the canvas opens with a [**Start**](/docs/postman-flows/reference/blocks/start/) block. You won't need to connect the **Start** block to any other blocks in this tutorial, but you can use it to trigger your flow in the future.

## Add a Repeat block

The **Repeat** block lets you build a loop that iterates over a count. For example, to run a loop three times, set the count to three.

In the next step, you'll use the **Number** block to define this count.

To add a **Repeat** block, do the following:

1. Right-click the canvas, and search for "repeat".
2. Click ![Repeat icon](https://assets.postman.com/postman-docs/aether-icons/action-repeat-stroke.svg#icon) **Repeat**.

A **Collect** block automatically appears on the canvas. You'll connect it later.

## Connect a Number 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 step, you'll use the **Number** block to define the number of times you want to run your loop.

To connect a **Number** block, do the following:

1. Hover over the **Repeat** block's **Count** input port. The pointer changes to a crosshair.
2. Drag the port from the **Repeat** block's **Count** input port to the location where you want to place the **Number** block.
3. Search for "number" and press **Return** or **Enter** to add ![Number icon](https://assets.postman.com/postman-docs/aether-icons/descriptive-number-stroke.svg#icon) **Number** from the list.
4. Enter a whole number. For example, if you want your loop to repeat three times, enter **3**.

## Connect an Evaluate block

Many programming languages start counting with an index value of zero (for example, 0, 1, 2).

In the following steps, you'll use an **Evaluate** block to add one to the count to start counting with an index value of one (for example, 1, 2, 3).

To connect an **Evaluate** block, do the following:

1. Hover over the **Repeat** block's output port. The pointer changes to a crosshair.
2. Drag the port to the location where you want to place the **Evaluate** block.
3. Select ![Code icon](https://assets.postman.com/postman-docs/aether-icons/descriptive-code-stroke.svg#icon) **Evaluate** from the list. If you want to search for the block, enter "Evaluate" in search.
4. Rename the variable. For example, enter **index**.
5. Add the following to the code editor:

   ```javascript
   index + 1
   ```

This code takes the index, which starts at zero, and adds one.

Alternatively, use the [Flows Query Language](/flows/reference/flows-query-language/introduction-to-fql/) (FQL) `$now()` function to timestamp the loop. This is another great way to conceptualize what happens when you run a loop.

## Connect a Collect block

The **Collect** block saves multiple outputs to a list. In this step, your loop will run three times, output three values, and use this block to save these values to a list.

To connect a **Collect** block, do the following:

1. Hover over the **Evaluate** block's **Result** ![Number icon](https://assets.postman.com/postman-docs/aether-icons/descriptive-number-stroke.svg#icon) output port. The pointer changes to a crosshair.
2. Drag the port to the location where you want to place the **Collect** block.
3. Select ![Collect icon](https://assets.postman.com/postman-docs/aether-icons/action-collect-stroke.svg#icon) **Collect** from the list. If you want to search for the block, enter "Collect" in search.

## Connect a Display block

The **Display** block displays incoming data, such as the **Collect** block's outgoing list.

To connect a **Display** block, do the following:

1. Hover over the **Collect** block's output port. The pointer changes to a crosshair.
2. Drag the port to the location where you want to place the **Display** block.
3. Select ![Output icon](https://assets.postman.com/postman-docs/aether-icons/action-output-stroke.svg#icon) **Display** from the list. If you want to search for the block, enter "Display" in search.

> **Tip**
>
> To auto-arrange the blocks on the canvas, click ![Auto layout icon](https://assets.postman.com/postman-docs/aether-icons/v12/icon-action-autoLayout-stroke.svg#icon) **Auto-organize flow** in the canvas toolbar.

## Run the flow

From the canvas toolbar, click ![Run icon](https://assets.postman.com/postman-docs/aether-icons/action-run-stroke.svg#icon) **Run**.

![Create a count-based loop flow](https://assets.postman.com/postman-docs/v12/postman-flows-count-based-loop-v12.png)

Congratulations! You created a count-based loop and displayed the result in a **Display** block.