[[https://github.com/tinkerpop/gremlin/raw/master/doc/images/gremlin-kilt.png]]
Determining the path that was traversed is useful in many applications. For example:
- What are the paths between
X
andY
according to a particular path description?
```text
gremlin> g.v(1)
==>v1
gremlin> g.v(1).out.name
==>vadas
==>lop
==>josh
gremlin> g.v(1).out.name.path
==>[v1, v2, vadas]
==>[v1, v3, lop]
==>[v1, v4, josh]
gremlin> g.v(1).outE.inV.name
==>[v1, v2, vadas]
==>[v1, v4, josh]
==>[v1, v3, lop]
gremlin> g.v(1).outE.inV.name.path
==>[v1, e7[1-knows→2], v2, vadas]
==>[v1, e9[1-created→3], v3, lop]
==>[v1, e8[1-knows→4], v4, josh]
```
If the path
step is provided closures then, in a round robin fashion, the closures are evaluated over each object of the path and that post-processed path is returned.
```
gremlin> g.v(1).outE.inV.path{it.name}{it.weight}{it.name}
==>[marko, 0.5, vadas]
==>[marko, 0.4, lop]
==>[marko, 1.0, josh]
gremlin> g.v(1).as(‘x’).outE.inV.loop(‘x’){it.loops < 3}.path{it.name}{it.weight}
==>[marko, 1.0, josh, 1.0, ripple]
==>[marko, 1.0, josh, 0.4, lop]
gremlin> g.v(1).as(‘x’).outE.inV.loop(‘x’){it.loops < 3}.path{it.id}
==>[1, 8, 4, 10, 5]
==>[1, 8, 4, 11, 3]
```
[[https://github.com/tinkerpop/gremlin/raw/master/doc/images/jerry-garcia.jpg]]
```text
g = new TinkerGraph()
g.loadGraphML(‘data/graph-example-2.xml’)
```
Using the Grateful Dead graph diagrammed in [[Defining a More Complex Property Graph]], lets determine the outE.inV
paths that exist between Dark Star and Jerry Garcia. Be sure to restrict this query to some max number of loops (less than 4 for this example) to prevent an infinite loop. The query below states:
- get vertex 89 (Dark Star)
- get the out going edges of the current vertex
- get the incoming (head) vertices of the current edge
- if the object hasn’t been looped 4 times, loop back to
outE
(emit, the object if its Jerry Garcia) - get the paths taken from Dark Star to Jerry Garcia
```text
gremlin> g.v(89).as(‘x’).outE.inV.loop(‘x’){it.loops < 4}{it.object.getProperty(‘name’)== ’Garcia’}.path
==>[v89, e7122[89-sung_by→340], v340]
==>[v89, e7021[89-followed_by→83], v83, e7158[83-sung_by→340], v340]
==>[v89, e7023[89-followed_by→206], v206, e7912[206-sung_by→340], v340]
==>[v89, e7006[89-followed_by→127], v127, e7786[127-sung_by→340], v340]
==>[v89, e7024[89-followed_by→49], v49, e7182[49-sung_by→340], v340]
==>[v89, e7025[89-followed_by→129], v129, e7102[129-sung_by→340], v340]
==>[v89, e7028[89-followed_by→130], v130, e7406[130-sung_by→340], v340]
==>[v89, e7018[89-followed_by→160], v160, e7082[160-sung_by→340], v340]
==>[v89, e7034[89-followed_by→91], v91, e7360[91-sung_by→340], v340]
==>[v89, e7017[89-followed_by→57], v57, e7126[57-sung_by→340], v340]
==>[v89, e7032[89-followed_by→140], v140, e7058[140-sung_by→340], v340]
==>[v89, e7015[89-followed_by→141], v141, e7108[141-sung_by→340], v340]
==>[v89, e7010[89-followed_by→94], v94, e7340[94-sung_by→340], v340]
==>[v89, e7029[89-followed_by→4], v4, e7064[4-sung_by→340], v340]
==>[v89, e7021[89-followed_by→83], v83, e1429[83-followed_by→5], v5, e7582[5-sung_by→340], v340]
==>[v89, e7021[89-followed_by→83], v83, e1434[83-followed_by→89], v89, e7122[89-sung_by→340], v340]
…
```