|{{Func|<pre>fn:for-each|( $seq input as item()*, $function action as function(item()) as item()*)|as item()*}}</pre>|-valign="top"
| '''Summary'''
|Applies the specified <code>$functionaction</code> to every item of <code>$seqinput</code> and returns all results as a single sequence.|-valign="top"
| '''Examples'''
|
''Result:'' <code>ONE TWO THREE</code>
</li></ul>
|-valign="top"
| '''XQuery 1.0'''
|At the core, for-each is nothing else than a simple FLWOR expression:
{|
|-valign="top"
| width='120' | '''Signature'''
|{{Func|<pre>fn:filter|( $seq input as item()*, $pred predicate as function(item()) as xs:boolean)|as item()*}}</pre>|-valign="top"
| '''Summary'''
|Applies the boolean predicate <code>$predpredicate</code> to all elements of the sequence <code>$seqinput</code>, returning those for which it returns <code>true()</code>.|-valign="top"
| '''Examples'''
|<ul><li>All even integers until 10:
''Result:'' <code>2 3 5 7 11 13 17 19</code>
</li></ul>
|-valign="top"
| '''Note'''
|<code>fn:filter</code> can be easily implemented with <code>fn:for-each</code>:
};
</syntaxhighlight>
|-valign="top"
| '''XQuery 1.0'''
|At the core, for-each is nothing else than a filter expression:
{|
|-valign="top"
| width='120' | '''Signature'''
|{{Func|<pre>fn:for-each-pair|( $seq1 input1 as item()*, $seq2 input2 as item()*, $function action as function(item(), item()) as item()*|) as item()*}}</pre>|-valign="top"
| '''Summary'''
|Applies the specified {{Code|$functionaction}} to the successive pairs of items of <code>$seq1input1</code> and <code>$seq2input2</code>. Evaluation is stopped if one sequence yields no more items.|-valign="top"
| '''Examples'''
|<ul><li>Adding one to the numbers at odd positions:
</syntaxhighlight>
''Result:'' <code>true false</code></li></ul>
|-valign="top"
| '''XQuery 1.0'''
|<syntaxhighlight lang="xquery">
{|
|-valign="top"
| width='120' | '''Signature'''
|{{Func|<pre>fn:fold-left|( $seq input as item()*, $seed zero as item()*, $function action as function(item()*, item()) as item()*|) as item()*}}</pre>|-valign="top"
| '''Summary'''
|The ''left fold'' traverses the sequence {{Code|$input}} from the left.The query <code>fn:fold-left(1 to 5, 0, $f)</code> , for example , would be evaluated as:
<syntaxhighlight lang="xquery">
$f($f($f($f($f(0, 1), 2), 3), 4), 5)
</syntaxhighlight>
|-valign="top"
| '''Examples'''
|<ul><li>Product of a sequence of integers:
''Result:'' <code>12345 42</code>
</li></ul>
|-valign="top"
| '''XQuery 1.0'''
|As folds are more general than ''FLWOR'' expressions, the implementation isn't as concise as the former ones:
{|
|-valign="top"
| width='120' | '''Signature'''
|{{Func|<pre>fn:fold-right|( $seq input as item()*, $seed zero as item()*, $function action as function(item(), item()*) as item()*|) as item()*}}</pre>|-valign="top"
| '''Summary'''
|The ''right fold'' <code>fn:fold-right($seq, $seed, $fun)</code> traverses the sequence {{Code|$input}} from the right.The query <code>fn:fold-right(1 to 5, 0, $f)</code> , for example , would be evaluated as: