# Loops (Repeating Code)

Another method of control is **repetition**. You wouldn't want to write all of the code that does something one hundred times. That would be like writing the same sentence one hundred times. For that, we ask the computer to do something repeatedly. We will look at *count-controlled* `for` loops and c*ondition-controlled* `while` or `do`  loops.

[**Khan Academy**](https://www.khanacademy.org/computing/computer-programming/programming#looping) employs something I really like\
&#x20;       **The Three Loop Questions**\
&#x20;       `1. What do I want to repeat?`\
`2. What do I want to change each time?`\
`3. How long should it repeat?`\
\
Select one of the following to learn more about the different types of loops (syntax listed below for quick reference).

{% content-ref url="/pages/-LOpFBpv3exQtYLUgHZx" %}
[For...Loop](/unit-3/loops/for-loop.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LKgJPC1rJ7f-IEQJMU6" %}
[While & Do/While Loops](/unit-3/loops/while-loop.md)
{% endcontent-ref %}

{% tabs %}
{% tab title="For Loop Syntax" %}
![Image by Author](/files/-LPm8HWLVOdtIUBDwh1v)
{% endtab %}

{% tab title="While Loop Syntax" %}
![Image by Author](/files/-LQKfqubMoK2K5tC9HWH)
{% endtab %}

{% tab title="Do While Syntax" %}
![Image by Author](/files/-LQKfxXCK3iMCbkysFS5)
{% endtab %}
{% endtabs %}


---

# 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://cs.brash.ca/unit-3/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.
