# Loop

The **Loop** component runs a set of components over and over, either a set
number of times or while a condition remains true. It is a good fit whenever a
flow needs to replay the same steps, for example, offering a menu again or
sending the caller back to an earlier point. This page covers what the component
does, how to configure it, and which component can follow it once the loop ends.

![The Loop component shown on the call flow canvas](/images/pbx/loop-component.png)

## Configure the loop

1. Drop the **Loop** component onto the canvas, then click it to open its
   settings.

   ![Opening the Loop component settings](/images/pbx/loop-component-cfd.png)

2. Choose a loop method, then click **Confirm**. The two methods are described
   below.

   **Loop until the fixed count is reached**

   ![Configuring the Loop component to repeat a fixed number of times](/images/pbx/loop-fixed-count.png)

   1. In the **Loop Method** drop-down list, select **Loop until the fixed
      count is reached**.
   2. In the **Count** field, enter how many times the loop should run.

      :::note
      The count can be any value from 1 to 99.
      :::

   **Loop while condition is true**

   ![Configuring the Loop component to repeat while a condition holds](/images/pbx/loop-condition.png)

   1. In the **Loop Method** drop-down list, select **Loop while condition is
      true**.
   2. In the **Expression** field, enter a function. For example,
      `FX_EQUAL($Session.ani,"1001")` enters the loop only when the caller ID is
      `1001`.

      :::note
      For the full list of variables and functions you can use in an expression,
      see [Variables and Functions in Cloud Voice Expressions](/pbx/call-flow-designer-guide/constants-and-variables-in-cloud-voice-cfd-expression/).
      :::

      :::caution
      Make sure the components inside the loop can eventually make the condition
      false. If the condition never changes, the caller stays in the loop and
      cannot move on, which ties up the call and the line.
      :::

3. Click ![Add component](/images/pbx/add-branch.png) inside the loop to add the
   components you want to repeat.

   :::note
   You can nest a **Loop** component inside another, up to **3 levels** deep.
   :::

   ![Nesting a Loop component inside another loop](/images/pbx/nesting-loop.png)

   The components you add appear inside the **Loop** component.

   ![Components placed inside the Loop component](/images/pbx/looped-component.png)

## Supported connections

A **Loop** component connects to exactly **one** component, which runs after the
loop finishes. You can connect any of the following.

| Component | Description |
|-----------|-------------|
| Prompt | Plays one or more audio prompts or a text-to-speech message to the caller. See [Prompt](/pbx/call-flow-designer-guide/prompt/). |
| Business Hours | Sends calls to different destinations depending on the time of day. See [Business Hours](/pbx/call-flow-designer-guide/business-hours/). |
| Menu | Offers callers a set of options and routes each call by the DTMF (Dual-Tone Multi-Frequency, the touch-tone keypad digit) key pressed. See [Menu](/pbx/call-flow-designer-guide/menu/). |
| User Input | Collects DTMF digits from the caller, often paired with **Condition** to evaluate what was entered and route the call. See [User Input](/pbx/call-flow-designer-guide/user-input/). |
| Language | Switches the system prompt language for the components that follow in the flow. See [Language](/pbx/call-flow-designer-guide/language/). |
| Record | Starts recording once the caller connects to another party, with optional prompts to announce recording at the start and while it runs. It can also turn recording off for calls that would otherwise be recorded. See [Record](/pbx/call-flow-designer-guide/record/). |
| Dial by Number | Lets callers dial a number directly to reach their destination. See [Dial by Number](/pbx/call-flow-designer-guide/dial-by-number/). |
| Dial by Name | An end component that closes the caller's path through the flow, letting them reach an extension user by keying the first three letters of that user's name. See [Dial by Name](/pbx/call-flow-designer-guide/dial-by-name/). |
| Transfer | An end component that hands the caller off to a chosen destination, with optional prompts to announce the transfer. See [Transfer](/pbx/call-flow-designer-guide/transfer/). |
| Hang Up Call | An end component that disconnects the call as soon as it is reached. See [Hang Up Call](/pbx/call-flow-designer-guide/hang-up-call/). |
| Condition | Branches calls by evaluating logical expressions. See [Condition](/pbx/call-flow-designer-guide/condition/). |
| Loop | Repeats a group of components, either a set number of times or until a condition is satisfied. See [Loop](/pbx/call-flow-designer-guide/loop/). |
| Internal Data Ops | Reads from and writes to the built-in PBX (Private Branch Exchange, the phone system) database. See [Get Extension Presence Status](/pbx/call-flow-designer-guide/get-extension-presence-status/), [Set Extension Presence Status](/pbx/call-flow-designer-guide/set-extension-presence-status/), [Get Queue Agent](/pbx/call-flow-designer-guide/get-queue-agent/), [Get Queue Info](/pbx/call-flow-designer-guide/get-queue-info/), [Get Agent Status](/pbx/call-flow-designer-guide/get-agent-status/), [Set Agent Status](/pbx/call-flow-designer-guide/set-agent-status/), [Get System Info](/pbx/call-flow-designer-guide/get-system-info/), [Get System Capacity](/pbx/call-flow-designer-guide/get-system-capacity/), [Get Extension Info](/pbx/call-flow-designer-guide/get-extension-info/), and [Get Company Contact Info](/pbx/call-flow-designer-guide/get-company-contact-info/). |
| Email Sender | Sends email from within the flow for real-time notifications, alerts, or user-specific details. See [Email Sender](/pbx/call-flow-designer-guide/email-sender/). |
| Database Access | Runs SQL operations against a database mid-flow to retrieve or update data. See [Database Access](/pbx/call-flow-designer-guide/database-access/). |
| HTTP Request | Sends HTTP requests to external web servers to exchange data with third-party services. See [HTTP Request](/pbx/call-flow-designer-guide/http-request/). |
