Branching Traversals 

Branching traversals allow decision points to be inserted into the traversal processing.

Branching traversals allow decision points to be inserted into the traversal processing. Prior to trying out branching traversals shown here, you must create the data as described in Simple Traversals.

This branching traversal example chooses between two labels, either author or reviewer to fork the traversal. If the vertex label is author, the edges labeled created are counted. If the vertex label is reviewer, the edges labeled rated are counted.
g.V().choose(label()).
  option('author', out('created').count()).
  option('reviewer', out('rated').count())
The output for this traversal lists each result, the count returned. This type of traversal is useful as an intermediary step in a query process, but clearly the output is not useful without reference.
==>0
==>0
==>2
==>0
==>0
==>0
==>2
==>1
==>0
==>0
==>0
==>3
==>0
==>2
==>2
==>1
==>2