# /while

## Syntax

**/while (condition) {**

`...`

**}**

## Description

Executes the commands between { and } while the expression condition evaluates to true. Note that } must be on a line by its own. You can end a /while loop immediately with /break or try the next iteration with /continue.

## Examples

```
/declare varname int 0
/while (${varname) < 5) {
  /varcalc varname ${varname}+1
  /echo ${varname}
}
```

Will output:

```
 1
 2
 3
 4
 5

/declare varname int 0
/while (${varname) < 5) {
  /varcalc varname ${varname}+1
  /if ({$varname} == 3) /continue
  /echo ${varname}
}
```

Will output:

```
 1
 2
 4
 5

/declare varname int 0
/while (${varname) < 5) {
  /varcalc varname ${varname}+1
  /if ({$varname} == 3) /break
  /echo ${varname}
}
```

Will output:

```
 1
 2
```

## See also

* [/for](/macroquest/commands/macro-commands/for.md)
* [/break](/macroquest/commands/macro-commands/break.md)
* [/continue](/macroquest/commands/macro-commands/continue.md)


---

# 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://macroquest.gitbook.io/macroquest/commands/macro-commands/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.
