> For the complete documentation index, see [llms.txt](https://metis-montessori-lyceum.gitbook.io/informatica/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://metis-montessori-lyceum.gitbook.io/informatica/modules/python/python-0/les-2b-loop-in-loops.md).

# Les 2b: Loop in Loops

Je kunt ook een loop in een ander loop gebruiken! Kijk maar eens naar het volgende figuur:

![](https://lh4.googleusercontent.com/dPQKL5SqYuwRxt6usb70DOU3DNVAcIJMguw8g_T5D0VxDOK0rUlrK81WY-y2dkjvI1b4TjSWCBJN5OFn2wncpW1DAKu9W2_Sfm9ktOpAkxo5NxUF6BlLG0wAdHUgSfyEzyXsJ-Wc)

We doen eigenlijk zes keer hetzelfde:

* teken vierkant
* draai 90 graden naar rechts
* loop langs een zijde
* draai 30 graden links

```python
import turtle
turtle.speed(0)

for _ in range(6):
  turtle.forward(30) # Het gele stuk tekent een vierkant
  turtle.right(90)
  turtle.forward(30)
  turtle.right(90)
  turtle.forward(30)
  turtle.right(90)
  turtle.forward(30)
  turtle.right(90)
  
  turtle.right(90)   # Draai 90 graden terug en
  turtle.forward(30) # loop langs de zijde
  turtle.left(30)   
```

Maar programmeurs houden niet van onnodige code. Het gele stuk bevat vier keer dezelfde twee regels! Dus daar maken we een loop van. En dan krijg je de code zoals hieronder:

```python
import turtle
turtle.speed(0)

for _ in range(6):
  for _ in range(4):   # een vierkant met een loop
    turtle.forward(30)
    turtle.right(90)
  
  turtle.right(90)
  turtle.forward(30)
  turtle.left(30)
```

### Opdracht 1

Teken:&#x20;

![](https://lh6.googleusercontent.com/5OBl-zOd1Vy0WBDzGRjYCoqUudg-RDSwXfARZRY3F-lIUFk9C_q2kWg-qJ9Biya8lC9Dd3YfYibtfDyPQxe8t4m45XGPGz5hwprYFo26427N7iJdG-G4sj5hY4h5HTExXlTqVUDS)

### Opdracht 2

Taken:

![](https://lh6.googleusercontent.com/YJIoFHuetQ-1a0KTIfUAGM08gf2jvMd-hqa4tgmDNcnzuiJMagTLx50-Tu1Bw4qVf69I7WKvHTBFyM2rnTePvYpS8ZCW21TU9vvp-IspgbXQtNASJ9_M3qUmRrL2wKfunj3uSFd9)

### **Opdracht 3**

Voer het volgende programma uit en bantwoord dan de vraag die onder de code staat:

```python
import turtle

turtle.shape("turtle")        

turtle.setheading(90)

for i in range(4):
    turtle.forward(100)
    turtle.right(90)

turtle.right(90)

for i in range(4):
    turtle.forward(100)
    turtle.right(90)

turtle.right(90)

for i in range(4):
    turtle.forward(100)
    turtle.right(90)

turtle.right(90)

for i in range(4):
    turtle.forward(100)
    turtle.right(90)

turtle.right(90)
```

Vraag: Kan dit programma korter? Zo ja, hoe?

### Wandel-mode (pen optillen)

In principe is de turtle steeds in *pen*-mode. Dit betekent dat hij steeds een lijn aan het tekenen is terwijl hij beweegt. De turtle kan ook in wandel-mode terecht. Dan kan hij bewegen, terwijl hij geen spoor nalaat. Je kunt tijdens het uitvoeren van een programma meerdere keren naar pen-mode of wandel-mode.

Door het commando `turtle.up()` in te geven kom je in wandel-mode terecht. \
Door het commando `turtle.down()` in te geven kom je in pen-mode terecht.

### Opdracht 4

a] Schrijf een programma dat de onderstaande tekening maakt.

![](https://lh4.googleusercontent.com/m1jHocK2w1IfQYTpISgIRp1MmIp50wZ7rH_1z0TB3zTdWbyManl7WtsI1-1A8E-EeoyPh4SqeTuhQfBIDTSKpiRM9cqAGp-zaRYJG9DMckOAKXnR70TLuwA42c8eKwqSoqswuEjk)

b] Schrijf een programma dat de onderstaande tekening maakt.

![](https://lh3.googleusercontent.com/Pr6hfSe47ZEc1jQcJzPZoqHaWevKcEe_bSMfsehS9ADeWrWxhox3Bruj4WuUk5D4jeKGsy5gNP71AXjOeO4TtebYU4Od-5j2NOg7uVrfarP4dFYAHnflD0HyMNUg6rJBQiNuOfxP)

### **Opdracht 5**

Maak de volgende figuren:

![](https://lh4.googleusercontent.com/7EKDWD3LYFyP46VK5c1BAem0UNwwYw6pA99mDxm1HBXpJl93gC5CD2uEvY9ZYKRGmyl07dOUv7xT4ED3Wb2yN51EO-IsBpk_16v3AaUqhD-A1lypJ8VjubmNfvarO8zf3En2dw0x)


---

# 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://metis-montessori-lyceum.gitbook.io/informatica/modules/python/python-0/les-2b-loop-in-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.
