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

# Branching Logic

> Conditional branches and states for dynamic agent workflow execution

Agents support conditional logic that lets the workflow take different paths based on data or page state during execution.

***

## Conditional Branches

The **Conditional Branch** instruction evaluates a condition and follows one of two paths:

* **TRUE path** — Instructions to execute when the condition is met
* **FALSE path** — Instructions to execute when the condition is not met

Conditions can check:

* Whether an element exists on the page
* The value of a variable
* The current URL
* The result of a JavaScript expression

Branches can be nested — a TRUE path can contain another conditional branch, allowing complex decision trees.

***

## States

States are named checkpoints within an agent workflow. Each state has:

| Property        | Description                        |
| --------------- | ---------------------------------- |
| **Name**        | State identifier                   |
| **Description** | What this state represents         |
| **Default**     | Whether this is the starting state |

States allow the agent to:

* **Resume from a known point** — If an execution is interrupted, it can restart from the last reached state
* **Branch based on current state** — Different instructions can execute depending on which state the agent is in

***

## Loop Over Data

The **Loop Over Data** instruction iterates over a data array, executing a set of child instructions for each item. This is useful for processing multiple records — for example, filling out a form for each candidate in a list.
