> ## Documentation Index
> Fetch the complete documentation index at: https://docs.odella.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Loops

> Using loops in Odella workflows

<Callout type="info">
  Loops allow you to repeat actions in Odella, automating tasks in your legal workflows. While they may seem complex initially, they’re incredibly useful.
</Callout>

## What is a Loop?

A loop repeats a set of actions until a specific condition is met—similar to saying, "Keep doing this until I say stop."

### Simple Loop Example

The simplest loop in Odella repeats actions until a stopping point is specified.

<Tip>
  Always connect an Output block to the 'Break' part of the loop to provide it with a clear stopping point.
</Tip>

## The Loop Controller

<Frame>
  <img src="https://mintcdn.com/odella/I7v1Fbrp2kx7rLoj/block-reference/assets/loop_controller_light.png?fit=max&auto=format&n=I7v1Fbrp2kx7rLoj&q=85&s=d24b1df8eaaf643aa9acd1da6294dbef" alt="Loop Controller Block Screenshot" className="block dark:hidden" width="880" height="554" data-path="block-reference/assets/loop_controller_light.png" />

  <img src="https://mintcdn.com/odella/I7v1Fbrp2kx7rLoj/block-reference/assets/loop_controller_dark.png?fit=max&auto=format&n=I7v1Fbrp2kx7rLoj&q=85&s=6fae976d825f4022aba117018cf10aec" alt="Loop Controller Block Screenshot" className="hidden dark:block" width="902" height="584" data-path="block-reference/assets/loop_controller_dark.png" />
</Frame>

The loop controller is the "brain" of your loop, managing how it operates. It’s the only block that can contain cycles of blocks, directing the flow of information through your loop.

### Key Parts of the Loop Controller

<CardGroup cols={2}>
  <Card title="Continue" icon="play">
    Controls whether the loop continues or stops, using a true/false value.
  </Card>

  <Card title="Input Pairs" icon="arrows-rotate">
    These are values that update with each cycle. Each pair has an input and an optional default input.
  </Card>
</CardGroup>

<Callout type="info">
  The default input provides an initial value, while the main input updates each cycle.
</Callout>

### Outputs in the Loop Controller

For each input pair (except 'Continue'), there’s an output. The first cycle uses the default value, while following cycles use the last output.

## Example: Loop in Action

Imagine a simple loop changing values 'A' and 'B'. In each cycle, 'A' and 'B' are updated, performing calculations or actions until a stop condition is met.

<Warning>
  Be sure to add a stopping condition to avoid an endless loop. Odella will automatically stop the loop if a maximum iteration count is reached.
</Warning>

## Practical Uses for Loops

### Adding Items to a List

Loops can add items to a list, ideal for gathering information across multiple steps.

<Callout type="info">
  The Array Block is set to Flatten by default, making it easy to add new items with each cycle of the loop.
</Callout>
