> ## Documentation Index
> Fetch the complete documentation index at: https://gql.ch/llms.txt
> Use this file to discover all available pages before exploring further.

# FOR

`FOR` statement unnests a list into individual records by iterating over its elements, allowing subsequent statements to process these elements one by one.

### Using FOR statement to iterate over each edge in a Quantified Path Pattern

Suppose we are interested in the all the hops required to go from Bayreuth to Santiago:

```mermaid theme={null}
%%{init: {'theme':'base', 'themeVariables': {'lineColor':'#F1FA8C','secondaryColor':'#F1FA8C','background':'#282A36'}}}%%
graph TB
    n1[Bayreuth, Germany 🇩🇪]
    n2[Nürnberg, Germany 🇩🇪]
    n3[Stuttgart, Germany 🇩🇪]
    n4[Frankfurt, Germany 🇩🇪]
    n5[Paris, France 🇫🇷]
    n6[Amsterdam, Netherlands 🇳🇱]
    n7[Rome, Italy 🇮🇹]
    n8[Santiago, Chile 🇨🇱]
    n1 -->|train 🚂| n2
    n2 -->|train 🚂| n1
    n2 -->|train 🚂 <br/>duration = 120| n3
    n2 -->|train 🚂| n4
    n4 -->|train 🚂| n5
    n3 -->|train 🚂| n5
    n5 -->|flight ✈️<br/>code = AF406<br/>duration = 780| n8
    n6 -->|flight ✈️| n8
    n6 -->|flight ✈️| n7
    n7 -->|car 🚙<br/>tolls = 74| n1
    n4 -->|train 🚂| n6


    classDef cityNode fill:#BD93F9,stroke-width:0px
    class n1,n2,n3,n4,n5,n6,n7,n8 cityNode
    
```

We can use the FOR loop as following

```gql theme={null}
match paths = any shortest  (a:city {_id:'Bayreuth'})-[edges:train|flight]->{1,}(b:city {_id:'Santiago'})
for edge in edges
return distinct table(edge._from, edge._to, labels(edge), pnodeIds(paths), length(paths));
```

We are using the FOR statement to unnest (decompose) the edges.
