Hello folks!
Someone at my workplace asked me a query – “how to exit in a loop in xquery?”. It is quite simple in other programming languages like – java, etc. just put a “break” in a loop and it comes out. Where as when it comes to XQuery, it is actually a bit tricky.
Most of you might already know this but for those who are still un-aware of it, Here it goes. I hope the below information helps!
Lets say, you have a list and you want to run some logic on each item of that list, and if the logic is met, don’t need to run through the entire list.
Below code just add some logic to a list and exit if the logic is met!
In this case, this will return the following result:
The catch is that the exit can only be written inside a function and it should only be a separate function.
Please share you idea of having an exit in the XQuery.
Anisha says
Hi, Thanks for this post. but which version of xquery you have used,as when I am trying to use this exit returning statement in XQuery, its not recongnising this and giving me error.
Abhishek says
This is XQuery 2.0 but if you can tell me which version you are using and what you are trying to do, I can give you an alternative option.
Saran says
How To do the same in Xquery 1.0 ?