# `while`

_Evaluate expressions while some condition remains true_
```syntax
while[test;e1;e2;e3;…;en]
```

Control construct. Where

- `test` is an expression that evaluates to an atom of integral type, typically a boolean
- `e1`, `e2`, … `en` are expressions

unless `test` evaluates to zero, q evaluates the expressions `e1` to `en` in order. The cycle (evaluate `test`, then the expressions) continues until `test` evaluates to zero.
```q
q)r:1 1
q)x:10
q)while[x-:1;r,:sum -2#r]
q)r
1 1 2 3 5 8 13 21 34 55 89
q)i:0
q)while[i<3;i+:1]
q)i
3
```

The result of `while` is always the [generic null](identity.md#null).

> **Warning — `while` is not a function but a control construct. You cannot iterate or project it.**
>
>
## Name scope

The brackets of the expression list do not create lexical scope.
Name scope within the brackets is the same as outside them.

----

[Accumulators – While](accumulators.md#while),
[`do`](do.md),
[`if`](if.md)


[Controlling evaluation](control.md)


_Q for Mortals_
[10.1.7 `while`](../learn/q4m/10_Execution_Control.md#1017-while)
