> For the complete documentation index, see [llms.txt](https://educacion.gitbook.io/programacion/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://educacion.gitbook.io/programacion/ud2-programacion-estructurada/estructuras-repetivas/bucles-anidados.md).

# Bucles anidados

A linguaxe Java ofrece a posibilidade de anidar bucles dentro de outros, esta é unha posibilidade interesante para procesar estructuras de datos multidimensionais e resolver probelas que requiren iteracións complexas.

```java
    for (int i=0; i<3; i++){
            for (int j=0; j<3; j++){
                System.out.println("i: " + i + ", j: "+ j);
            }
        }
//SAIDA
i: 0, j: 0
i: 0, j: 1
i: 0, j: 2
i: 1, j: 0
i: 1, j: 1
i: 1, j: 2
i: 2, j: 0
i: 2, j: 1
i: 2, j: 2
```

Os bucles anidados son útiles para recorrer **arrays ou listas multidimensionales, xerar patróns de figuras ou combinacións de valores.**

## Consideracións

**Complexidade:** Os bucles anidados incrementan a complexidade temporal (O(n²) para dous bucles, O(n) para un)

**Lexibilidade:** É importante manter o código lexible con nomes de variables descritivos


---

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

```
GET https://educacion.gitbook.io/programacion/ud2-programacion-estructurada/estructuras-repetivas/bucles-anidados.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.
