# While

Цикл [`while`](https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/while)выполняет выражения, пока условие истинно. Выглядит он так:

```javascript
while (условие)
  выражения
```

Если `условие` становится ложным, выражения в цикле перестают выполняться и управление переходит к выражению после цикла.

`Условие`проверяется на истинность до того, как выполняются `выражения` в цикле. Если `условие`истинно, выполняются `выражения`, а затем условие проверяется снова. Если `условие` ложно, выполнение приостанавливается и управление переходит к выражению после `while`.

Пример:

```javascript
var n = 0;
var x = 0;
while (n < 3) {
  n++;
  x += n;
}
```

С каждой итерацией цикл увеличивает `n`и добавляет это значение к `x`. Поэтому `x`и `n` получают следующие значения:

* После первого прохода: `n`= 1 и`x`= 1
* После второго:`n`= 2 и`x`= 3
* После третьего прохода:`n`= 3 и`x`= 6


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://andersenlab.gitbook.io/javascript/js-basics/loops/while.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
