---
title: "Iteration"
canonical: "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/AssociativeArrays/Iteration.html"
source: "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/AssociativeArrays/Iteration.md"
part: "Sets, Sequences, and Mappings"
chapter: "Associative Arrays"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Sets, Sequences, and Mappings", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/index-sets-sequences-mappings.md"}
  - {"title": "Associative Arrays", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/AssociativeArrays/index-associative-arrays.md"}
prev: {"title": "Operations", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/AssociativeArrays/operations.md"}
next: {"title": "Coproducts", "source": "https://docs.magma-maths.org/v2.30-1/SetsSequencesMappings/Coproducts/index-coproducts.md"}
intrinsics:
  - {"name": "in", "signature": "v in A"}
  - {"name": "in", "signature": "k -> v in A"}
examples:
  - "ex-adf920"
---

# Iteration

<a id="literal-literal-in-v-in-a"></a>
## `v in A`

<a id="literal-literal-in-k-v-in-a"></a>
## `k -> v in A`

Iteration over the values in an associative array is supported as usual; in the forms above, $v$ will take the value of successive elements in the associative array. If the dual iteration form is used then additionally $k$ will take on the value of the associated key.

<a id="example-ex-adf920"></a>
## `Example: Iterating over an Associative Array (ex-adf920)`

We revisit the first part of the above example and print the elements out using the dual iteration.

```magma
> A := AssociativeArray();
> A[1/2] := 7;
> A[3/8] := "abc";
> A[3] := 3/8;
> for k -> v in A do k, v; end for;
1/2 7
3/8 abc
3 3/8
```
