---
title: "While Controller"
description: "Configure the JMeter While Controller logic controllers: properties, defaults, and practical usage notes for building reliable load tests."
url: https://docs.jmeter.ai/components/while-controller/
lastUpdated: 2026-10-01
source: docs.jmeter.ai
---

# While Controller

*Part of the **Logic Controllers** category. Also documented in context in the [full Component Reference](/user-manual/component-reference/#while-controller).*

**TL;DR:** the While Controller repeats its children as long as a condition stays true (or forever, if left blank, until the enclosing loop/thread stops) — the standard element for polling patterns like “keep checking job status until it’s done.”

![While Controller](/images/screenshots/whilecontroller.png)

The While Controller runs its children until the condition is “`false`”.

> **Note**
> JMeter will expose the looping index as a variable named `__jm__&lt;Name of your element&gt;__idx`. So for
> example, if your While Controller is named WC, then you can access the looping index through `\${__jm__WC__idx}`.
> Index starts at 0

Possible condition values:

- blank - exit loop when last sample in loop fails
- `LAST` - exit loop when last sample in loop fails. If the last sample just before the loop failed, don’t enter loop.
- Otherwise - exit (or don’t enter) the loop when the condition is equal to the string “`false`”

> **Note**
> The condition can be any variable or function that eventually evaluates to the string “`false`”.
> This allows the use of `[__jexl3](/functions/jexl3/)`, `[__groovy](/functions/groovy/)` function, properties or variables as needed.

> **Note**
> Note that the condition is evaluated twice, once before starting sampling children and once at end of children sampling, so putting
> non idempotent functions in Condition (like `[__counter](/functions/counter/)`) can introduce issues.

For example:

- `\${VAR}` - where `VAR` is set to false by some other test element
- `\${__jexl3(\${C}==10)}`
- `\${__jexl3("\${VAR2}"=="abcd")}`
- `\${_P(property)}` - where property is set to “`false`” somewhere else

| Name | Required | Description |
| --- | --- | --- |
| Name | No | Descriptive name for this controller that is shown in the tree, and used to name the transaction. |
| Condition | No | blank, `LAST`, or variable/function |

### Common gotchas

- **A blank condition means loop forever** (until the thread is told to stop) — a very common way to accidentally hang a test plan; always set an explicit exit condition or a max-iteration guard variable.
- The condition is re-evaluated **after** each pass through the children, so the loop always runs at least once — model that if your logic assumes a “check first, then maybe run” pattern.
- Same JavaScript-expression syntax as [If Controller](/components/if-controller/) (`"${done}" != "true"`), including the same quoting pitfalls.
- For polling with a bounded wait, pair with a Constant Timer inside the loop (see [Timers, Think Time & Pacing](/topics/timers-pacing-throughput-modeling/)) so you’re not hammering the endpoint every iteration.

## Related

- [Logic Controllers & Flow Control](/topics/logic-controllers-flow-control/)
- [Full Component Reference](/user-manual/component-reference/)
- [Functions and Variables](/user-manual/functions/)
