> 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.md).

# Iteration (Loops)

#### Iteration (Loops) in Computer Programming

Iteration, commonly known as looping, is a fundamental concept in computer programming that allows a block of code to be executed repeatedly, based on a specified condition. This process enables programmers to efficiently manage repetitive tasks by reducing the amount of code they need to write and maintain.

**Types of Iteration**

There are several types of loops, but the most commonly used ones include:

* **For Loop**: Executes a block of code a predetermined number of times.
* **While Loop**: Repeats a block of code as long as a specified condition is true.
* **Do-While Loop**: Similar to the while loop, but it executes the block of code once before checking the condition.
* **For-Each Loop:** The for-each loop, also known as the enhanced for loop, is a special type of loop that simplifies the iteration over collections, such as arrays. It eliminates the need for using a counter or index variable to access the elements of the array or collection.

#### Using Loops with Arrays

Loops are often used in conjunction with arrays to perform operations on each element of the array. For example, a for loop can be used to iterate over the elements of an array, performing calculations, displaying them, or modifying them as needed.


---

# 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.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.
