# If statement in the for loop

**URL:** <https://community.neo4j.com/t/if-statement-in-the-for-loop/14060>\
**Category:** Neo4j Graph Platform\
**Created:** [January 27, 2020, 5:42am UTC](https://community.neo4j.com/t/if-statement-in-the-for-loop/14060 "2020-01-27T05:42:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaini.kiran](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jaini.kiran/32/9706_2.png) [@jaini.kiran](https://community.neo4j.com/u/jaini.kiran)\
**Post date:** [January 27, 2020, 5:42am UTC](https://community.neo4j.com/t/if-statement-in-the-for-loop/14060/1 "2020-01-27T05:42:25Z")

</div>

I am new to neo4j.

```auto
MATCH (s:Bus{bus_no:14}), (l:Bus{bus_no:12})
CALL algo.shortestPath.stream(s, l, "length")
YIELD nodeId,cost
with collect(nodeId) as q
MATCH p= (a)-[r:TRANSMISSION_LINE]-(b)
where id(a)in q and id(b) in q
with distinct(r) as rls
return collect(rls) as e

```

This query returns a list of relationships.  
Every relationship has a property called `available_cap`.  
`l` is a node having a property called `load`

i want to do  
for every rls in e  
if `rls.availale_cap > l.load` then print( 'ok you can connect')  
else print ('you should not connect')

Please help me.

---

<div class="post-metadata">

**Author:** ![julie.fisher](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/julie.fisher/32/3870_2.png) [@julie.fisher](https://community.neo4j.com/u/julie.fisher)\
**Post date:** [January 27, 2020, 4:20pm UTC](https://community.neo4j.com/t/if-statement-in-the-for-loop/14060/2 "2020-01-27T16:20:52Z")

</div>

You want a case statement. So the if statement turns into something like this:

```auto
MATCH (s:Bus{bus_no:14}), (l:Bus{bus_no:12})
CALL algo.shortestPath.stream(s, l, "length")
YIELD nodeId,cost
with collect(nodeId) as q
MATCH p= (a)-[r:TRANSMISSION_LINE]-(b)
where id(a)in q and id(b) in q
with distinct(r) as rls
RETURN
CASE
WHEN rls.availale_cap > l.load THEN 'okay you can connect'
ELSE 'you should not connect' END AS status

```

I'm not sure exactly how you want to use this or how you want the results formatted, but the above should return one row per rls with a single 'status' column which has one of the two print statements.

For more information on case statements, you can check out the [Expressions section](https://neo4j.com/docs/cypher-manual/current/syntax/expressions/) of the Cypher manual and go to 2.3.3 CASE expressions.

---

<div class="post-metadata">

**Author:** ![jaini.kiran](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jaini.kiran/32/9706_2.png) [@jaini.kiran](https://community.neo4j.com/u/jaini.kiran)\
**Post date:** [February 4, 2020, 7:29am UTC](https://community.neo4j.com/t/if-statement-in-the-for-loop/14060/3 "2020-02-04T07:29:50Z")

</div>

Thanks for the reply.

---

<div class="post-metadata">

**Author:** ![julie.fisher](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/julie.fisher/32/3870_2.png) [@julie.fisher](https://community.neo4j.com/u/julie.fisher)\
**Post date:** [February 4, 2020, 3:42pm UTC](https://community.neo4j.com/t/if-statement-in-the-for-loop/14060/4 "2020-02-04T15:42:53Z")

</div>

You're welcome. Hope it helped.

---

<div class="post-metadata">

**Author:** ![jaini.kiran](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jaini.kiran/32/9706_2.png) [@jaini.kiran](https://community.neo4j.com/u/jaini.kiran)\
**Post date:** [February 5, 2020, 12:52pm UTC](https://community.neo4j.com/t/if-statement-in-the-for-loop/14060/5 "2020-02-05T12:52:33Z")

</div>

can please help me for the problem in below link....

[https://community.neo4j.com/t/how-to-extract-relationships-from-shortest-path-algorithm/14377](https://community.neo4j.com/t/how-to-extract-relationships-from-shortest-path-algorithm/14377)
