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.