---
title: "While"
description: "Run the body while a condition matches, up to a max count."
canonical_url: "https://docs.vettero.com/build/workflows/blocks/loops/while"
---
# While

> Run the body while a condition matches, up to a max count.

<block-meta block="Yes" channels="Any" folder="basic/loops" group="Loops" groupTo="/build/workflows/blocks/loops" icon="i-lucide-refresh-cw" pipe="Value" scope="Any" tool="No" type="loop.while">



</block-meta>

**While** checks a **condition** (query) **before** each iteration. If it matches, it runs the **callback** body, then checks again. If it does not match, the main path continues. A missing or empty condition fails the run.

Use [Do While](https://docs.vettero.com/build/workflows/blocks/loops/do-while) when the body must run once before the condition is checked. Use [For](https://docs.vettero.com/build/workflows/blocks/loops/for) when the count is known up front.

## Configure

<table>
<thead>
  <tr>
    <th>
      Setting
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        Condition
      </strong>
    </td>
    
    <td>
      Required query (AND/OR, rules, nested groups, <strong>
        Not
      </strong>
      
      ), same builder as <a href="https://docs.vettero.com/build/workflows/blocks/condition/condition">
        Condition
      </a>
      
      . Left-side fields come from this block’s context, plus <code>
        args.index
      </code>
      
       for the upcoming iteration
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Max iterations
      </strong>
      
       (optional)
    </td>
    
    <td>
      Safety cap. Defaults to <code>
        1000
      </code>
      
      . Must be greater than <code>
        0
      </code>
    </td>
  </tr>
</tbody>
</table>

The condition owns continue/stop. The body’s **return** is only collected on the pipe; it does not decide whether to loop again.

The **Callback** outlet must be connected to a [Lambda](https://docs.vettero.com/build/workflows/blocks/module/lambda) block. If it is not connected, the run fails.

## Handles

<table>
<thead>
  <tr>
    <th>
      Handle
    </th>
    
    <th>
      Role
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        In
      </strong>
      
       (target)
    </td>
    
    <td>
      Incoming connection
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Out
      </strong>
      
       (source)
    </td>
    
    <td>
      Continues after the loop finishes (main path, same scope)
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Callback
      </strong>
    </td>
    
    <td>
      <strong>
        New callback scope
      </strong>
      
       for each iteration. Connect to <a href="https://docs.vettero.com/build/workflows/blocks/module/lambda">
        Lambda
      </a>
    </td>
  </tr>
</tbody>
</table>

Inside the body (after Lambda), use:

<table>
<thead>
  <tr>
    <th>
      Path
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        args.index
      </code>
    </td>
    
    <td>
      Zero-based iteration count (<code>
        0
      </code>
      
      , <code>
        1
      </code>
      
      , <code>
        2
      </code>
      
      , …)
    </td>
  </tr>
</tbody>
</table>

End the body with a **return** to collect a value for this iteration. [Continue](https://docs.vettero.com/build/workflows/blocks/loops/continue) skips the rest of this pass. [Break](https://docs.vettero.com/build/workflows/blocks/loops/break) stops the loop early. An unconnected **Out** ends the main path after the loop.

## Pipe schema

The next block on the main path reads this on the data pipe (`pipe.value`).

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Results
    </td>
    
    <td>
      list
    </td>
    
    <td>
      Values <strong>
        return
      </strong>
      
      ed from each iteration, in order
    </td>
  </tr>
</tbody>
</table>

## Use case

- Keep retrying or polling while a variable or pipe value still matches a rule (status is `open`, flag is true).
- Cap with **Max iterations** so a still-true condition cannot run forever.
- **Return** a mapped result from the body (not `true`/`false` for looping). Use [Continue](https://docs.vettero.com/build/workflows/blocks/loops/continue) to skip the rest of this pass, or [Break](https://docs.vettero.com/build/workflows/blocks/loops/break) to stop from a nested branch.

<block-page-nav>



</block-page-nav>


## Sitemap

See the full [sitemap](https://docs.vettero.com/sitemap.md) for all pages.
