It seems that you are asking two different questions.
About whether it is possible to use loops in Cypher, yes, you can, FOREACH or UNWIND , depending on what you want to achieve. This is a good resource when you do not quite know what is right for your business. He compares these two and tries them with different sample queries.
Depending on whether you can write a user-defined function, with Neo4j 3.0 you can. However, they are written in Java. Take a look at this link for more details: https://neo4j.com/developer/procedures-functions/
source share