title: Recursive function returning boolean, with a for loop inside
body: <p>My data is a binary tree, and will check through every child, returning true if it finds the data i want, if not, it keeps looking for it.
  In some way i want to return the variable @exists or something.. Well anyone might have a solution for my problem. I was thinking something like this but i couldn't get it to work! (code-snippet)</p>
  
  <pre><code>declare function local:test($id as xs:integer, $topic as xs:integer) as xs:boolean {
      let $exists := fn:false()
      for $x in ...
      return
          if .. then
              set exists to fn:true()
          else
              set exists to exists OR local:test($x,$topic)
  
      return @exists in some way  
  };
  </code></pre>