# While Loops

`while` loops are the fastest, most basic loop. Due to the simplicity of this block, most programmers are very familiar with this construct. Parenthesis are optional on these.

The usage is:

```swift
while <condition> {
    <code block>
}
```

As long as the condition is true, the code block will execute. Once, or if, the condition is false, the loop will stop executing and the program will continue.

An example of the use is:

```swift
var input
while !( (input = IO.prompt("[Y/n]> ")) in "Yn" ) {
    print "Please enter either 'Y' or 'N'"
}
print "You inputted '#{input}'"
```

When run, an example execution is:

```
[Y/n]> No
Please enter either 'Y' or 'N'
[Y/n]> Yes
Please enter either 'Y' or 'N'
[Y/n]> Y
You inputted 'Y'
```


---

# 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://docs.cheddar.vihan.org/docs/control-flow/loops/while-loops.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.
