> For the complete documentation index, see [llms.txt](https://university-west.gitbook.io/programming-paradigms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university-west.gitbook.io/programming-paradigms/programming-fundamentals/control-structures/iteration-loops/do-while-loops.md).

# Do-While loops

#### Do-While Loop Statement in Computer Programming

The do-while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given Boolean condition at the end of each iteration. Unlike the `while` loop, which tests the loop condition before the block of code runs, the `do-while` loop checks its condition after the code has executed. This ensures that the block of code inside the loop executes at least one time.

**Syntax:**

```c
do {
    // Code block to be executed
} while (condition);
```

**Example in C#:**

```csharp
using System;

class Program {
    static void Main() {
        int counter = 0;
        do {
            Console.WriteLine(counter);
            counter++;
        } while (counter < 5);
    }
}
```

**Note:** Python does not have a built-in `do-while` loop construct. Instead, a similar effect can be achieved using a while loop. Here is an equivalent approach in Python:

**Example in Python:**

```python
counter = 0
while True:
    print(counter)
    counter += 1
    if counter >= 5:
        break
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://university-west.gitbook.io/programming-paradigms/programming-fundamentals/control-structures/iteration-loops/do-while-loops.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
