# Branches and OR Logic

Source: https://rungs.dev/docs/ladder-logic/branches-and-or-logic

> Use parallel branches in Ladder Logic to express OR conditions in rungs.dev. Series contacts AND together; parallel branches OR — combine them for any boolean rule.

A **branch** is a parallel path on a rung. Power flows through the rung if **any one** of the parallel paths is true. Branches are how Ladder Logic expresses OR.

## Series = AND [#series--and]

Contacts placed in series on the same horizontal line are ANDed:

```ladder
XIC(A)XIC(B)OTE(Out)
```

`Out` is energized when `A AND B` are both true.

## Parallel = OR [#parallel--or]

Contacts placed in parallel branches are ORed:

```ladder
[XIC(A),XIC(B)]OTE(Out)
```

`Out` is energized when `A OR B` is true.

> **IDEA**
>
> **Practice**
>
> Try both in Learn: [Either-Button Lamp](https://rungs.dev/exercises/either-button-lamp) for OR logic, and [Two-Button Lamp](https://rungs.dev/exercises/two-button-lamp) for AND.

## Combining Series and Parallel [#combining-series-and-parallel]

You can mix both on one rung. This is the classic **start/stop seal-in**:

```ladder
[XIC(Fault),XIC(Alarm)]XIO(Reset)OTE(Alarm)
```

- When `Fault` goes true, `Alarm` energizes.
- The `Alarm` contact in the lower branch keeps the rung true even after `Fault` clears — the alarm is now "sealed in".
- Pressing `Reset` breaks the series path and drops `Alarm` back to `0`.

## Multi-Level Branches [#multi-level-branches]

A single branch can have more than two parallel paths — each path is another level:

```ladder
[XIC(A),XIC(B),XIC(C)]OTE(Out)
```

`Out` is energized when `A OR B OR C` is true. Add as many levels as you need; the rung stays flat and readable.

## Nested Branches [#nested-branches]

Branches can contain further branches. Keep nesting shallow — two or three levels. Deeply nested rungs become unreadable; split them into multiple rungs instead.

```ladder
[[XIC(A),XIC(B)]XIC(C),XIC(D)]OTE(Out)
```

`Out` is energized when `((A OR B) AND C) OR D` is true — the inner branch (`A OR B`) sits inside a path of the outer branch.

## Adding a Branch in Rungs Studio [#adding-a-branch-in-rungs-studio]

The Ladder Logic toolbar sits at the top of the editor. Use the branch tool  in the toolbar to insert a parallel path on a rung. To add another parallel path to an existing branch, select a circuit and click the branch-level tool . Drop contacts into the new branch like any other instruction.

## Tips [#tips]

- Each branch should do one thing. If a branch gets long, promote it to its own rung.