# LIMIT — Range Check

Source: https://rungs.dev/docs/ladder-logic/instructions/limit

> LIMIT in rungs.dev passes power when a test value is inside [lowLimit, highLimit]; if lowLimit is greater than highLimit, the bounds reverse to outside-the-band.

Passes power when test is inside the inclusive range [lowLimit, highLimit]; bounds reverse to outside-the-band when lowLimit > highLimit.

## Operands [#operands]

| Name        | Type                                |
| ----------- | ----------------------------------- |
| `lowLimit`  | `DINT` \| `INT` \| `SINT` \| `REAL` |
| `test`      | `DINT` \| `INT` \| `SINT` \| `REAL` |
| `highLimit` | `DINT` \| `INT` \| `SINT` \| `REAL` |

## How It Works [#how-it-works]

- When `lowLimit` ≤ `highLimit` (the usual case): the rung passes when `lowLimit` ≤ `test` ≤ `highLimit`. Bounds are inclusive.
- When `lowLimit` > `highLimit` (wraparound): the rung passes when `test` ≥ `lowLimit` **or** `test` ≤ `highLimit`. Useful for ranges that span a wrap boundary, e.g. an angle check across `0°`.
- If any operand is `NaN`, the rung is blocked.

## Example — Value in Range [#example--value-in-range]

Energize `InRange` while `Pressure` is between 20 and 100.

```ladder
LIMIT(20,Pressure,100)OTE(InRange)
```

Equivalent to `GE(Pressure, 20) LE(Pressure, 100) OTE(InRange)` but in one instruction.

## Example — Wraparound [#example--wraparound]

Energize `NearHome` when a heading is within ±10° of 0°. Use the wraparound form:

```ladder
LIMIT(350,Heading,10)OTE(NearHome)
```

Here `lowLimit = 350` and `highLimit = 10`, so the rung passes when `Heading ≥ 350` or `Heading ≤ 10`.

## Example — Out of Range [#example--out-of-range]

Swap the bounds to get "outside the band". `LIMIT(20, Sensor, 80)` passes when `Sensor` is between 20 and 80; `LIMIT(80, Sensor, 20)` passes when it is below 20 or above 80.

```ladder
LIMIT(20,Sensor,80)OTE(InRange);LIMIT(80,Sensor,20)OTE(OutOfRange)
```

> **WARNING**
>
> **Boundaries overlap**
>
> Both forms are inclusive, so at the exact bounds (`Sensor = 20` or `Sensor = 80`) `InRange` **and** `OutOfRange` are both `1`. If the two must be mutually exclusive, use `GT` / `LT` on one side instead of a second `LIMIT`.

## Common Mistakes [#common-mistakes]

- Using `LIMIT` on a `BOOL` tag — numeric operands only. For boolean gating, use `XIC` / `XIO`.
- Forgetting that a single-band check with `low > high` flips to wraparound semantics. If you just want "between", always pass `low ≤ high`.

## Related [#related]

- [Compare instructions](https://rungs.dev/docs/ladder-logic/instructions/compare) — `GE` / `LE` pair with more flexibility
- [Math instructions](https://rungs.dev/docs/ladder-logic/instructions/math) — compute values to compare
- [Bit instructions](https://rungs.dev/docs/ladder-logic/instructions/bit-instructions) — boolean examine