# Rungs and Power Flow

Source: https://rungs.dev/docs/ladder-logic/rungs-and-power-flow

> Learn how Ladder Logic rungs evaluate power flow between two rails in rungs.dev — series ANDs, parallel ORs, and how outputs are energized scan by scan.

A Ladder Logic program is a stack of horizontal **rungs** drawn between two vertical **power rails**. Each rung represents one logical condition-and-action pair.

```ladder
XIC(Switch1)XIC(Switch2)OTE(Lamp);XIC(DoorSensor)OTE(Alarm)
```

The left rail is the "power source". The right rail is "ground". The instructions between them decide whether power reaches the output on the right.

## How a Rung Evaluates [#how-a-rung-evaluates]

- Instructions are read **left to right**.
- Contacts in **series** are ANDed together — power only flows if all are true.
- Contacts in **parallel** branches are ORed — power flows if any branch is true.
- If the rung is true, the output coil on the right is energized.

Rung 0 energizes `Lamp` only when `Switch1` AND `Switch2` are both `1` — contacts in series are ANDed. Rung 1 is independent: `Alarm` follows `DoorSensor`.

> **IDEA**
>
> **Practice**
>
> Try it in the [Two-Button Lamp exercise](https://rungs.dev/exercises/two-button-lamp) — light a lamp only while two buttons are pressed together (series AND).

## Rungs run every scan [#rungs-run-every-scan]

The PLC re-evaluates your whole program — every rung, top to bottom — over and over in a loop called the **scan**, so an output always reflects the latest inputs. That ordering has consequences beyond logic: it sets the _timing_ of your outputs, and when two rungs drive the same output the lower one wins. Both are covered in [The Scan Cycle](https://rungs.dev/docs/scan-cycle/the-scan-cycle) and [Scan Order and One-Scan Delays](https://rungs.dev/docs/scan-cycle/scan-order-and-one-scan-delays).

## Adding a Rung in Rungs Studio [#adding-a-rung-in-rungs-studio]

The Ladder Logic toolbar sits at the top of the editor. Use the rung tool  to insert a new rung. Click it to add a rung below the currently selected rung, or drag it onto the program to drop a rung where you want it.

## Summary [#summary]

- Rungs evaluate left-to-right, top-to-bottom, every scan.
- Series = AND. Parallel = OR.
- Outputs re-energize every scan based on current conditions.
- Each output should be driven by a single rung.