---
title: "Do While"
description: "Run the body at least once, then continue while a condition matches."
canonical_url: "https://docs.vettero.com/build/workflows/blocks/loops/do-while"
---
# Do While

> Run the body at least once, then continue while a condition matches.

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



</block-meta>

**Do While** always runs the **callback** body **once**, then checks a **condition** (query) before further iterations. If the condition matches, it runs again. If it does not, the main path continues. A missing or empty condition fails the run (the body does not start).

Use [While](https://docs.vettero.com/build/workflows/blocks/loops/while) when the condition should be checked **before** the first run. 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 after the first pass. 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

- Always send or look up once, then repeat only while a status or flag still matches.
- Retry a step that must run before you know whether to continue.
- Cap with **Max iterations**. **Return** mapped results from the body; 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.
