# 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="loops/for-loop" %}
[for-loop](https://cs.brash.ca/unit-3/loops/for-loop)
{% endcontent-ref %}

{% content-ref url="loops/while-loop" %}
[while-loop](https://cs.brash.ca/unit-3/loops/while-loop)
{% endcontent-ref %}

{% tabs %}
{% tab title="For Loop Syntax" %}
![Image by Author](https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LPm84nKzSF9hQLJFc58%2F-LPm8HWLVOdtIUBDwh1v%2FFor%20Loop.png?alt=media\&token=33474e74-f649-4651-bdcc-9a179c4a2687)
{% endtab %}

{% tab title="While Loop Syntax" %}
![Image by Author](https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LQKfUa_-vF3sgK9kedq%2F-LQKfqubMoK2K5tC9HWH%2FWhile%20Loop.png?alt=media\&token=ca862841-2e2b-46e1-8cfc-16464c40d342)
{% endtab %}

{% tab title="Do While Syntax" %}
![Image by Author](https://1200419583-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LKbpNQDFNJap9OTDSt6%2F-LQKfUa_-vF3sgK9kedq%2F-LQKfxXCK3iMCbkysFS5%2FDo%20While%20Loop.png?alt=media\&token=2bf1a8bc-0f4a-4767-a72d-388b55fde24d)
{% endtab %}
{% endtabs %}
