choose步骤允许创建类似大多数编程语言中常见的if then else这样的结构的查询。如果用Java语言编写程序,我们会发现我们写了类似下面这样的代码。
The choose step allows the creation of queries that are a lot like the "if then else" constructs found
in most programming languages. If we were programming in Java we might find ourselves writing
something like the following.
 

 

小精灵为我们提供了一种方式可以做同样的事。下面的查询是找到所有在Texas的机场,如果机场有大于12000英尺长的跑道,就返回code属性的值,否则就返回描述信息。

Gremlin offers us a way to do the same thing. The query below finds all the airports in Texas and
then will return the value of the code property if an airport has a runway longer than 12,000 feet
otherwise it will return the value of the desc.

 

运行查询返回结果像下面这样。

When run the output returned should look like this.

 

如果choose步骤的else部分没有提供内容,那么它的行为就是简单的if判断。

 
If the "else" part of the choose step is not provided then it behaves as a simple "if".

 

 

 在这个例子中,else是隐含的,choose步骤接收到的元素的信息如下所示。
The "else" in this case is implied and the incoming element that the choose step received is passed
on as shown below.
 

 

这是另一个用到同样结构的例子。

Here is another example that uses the same constructs.

 

 

posted on 2022-04-18 21:17  bokeyuannicheng0000  阅读(10)  评论(0)    收藏  举报