# SimpleLoop

Creates a loop based on an input map element.

The SimpleLoop function specifies that the output map element associated with the loop expression tab is to loop corresponding to the value of the input map element argument expression.

When an input map element is mapped to an output map element that loops, the SimpleLoop function is automatically created at the nearest ancestor looping output element to define the loop. If no sort keys are specified, the order of the output is the same order as the input elements.

This function can only be used in the Loop tab or as part of an Aggregate expression.

## Related examples

* [Grouping loop iterations](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/8.0/grouping-loop-iterations)
* [Mapping nested loops](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/8.0/mapping-nested-loops)
* [Filtering loop elements on their value](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/8.0/filtering-loop-elements-on-their-value)
* [Sorting loop elements](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/8.0/sorting-loop-elements)
* [Returning a loop index](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/8.0/returning-loop-index)
* [Applying functions to collections of elements](https://help.qlik.com/talend/en-US/data-mapper-functions-reference-guide/8.0/applying-functions-to-collections-of-elements)

## Arguments

| Arguments | Definitions |
| --- | --- |
| Input Map Element | Add a looping<br>element from the input structure. |
| Filter | Specify an expression that returns a Boolean.<br>This expression is evaluated for each instance of the loop. If this<br>filter expression returns true, the instance is included in the loop. If it<br>returns false,<br>the instance is excluded from the loop. |
| Sort Keys | Use the AscendingSort or<br>DescendingSort function to sort loop<br>iterations. You can use as many as needed. |
| Contexts | Specify the context using the EnclosingContext or NestedContext function. EnclosingContext specifies the<br>output map element that encloses this loop. If not specified, the<br>nearest looping ancestor map element is used. |

## Properties

| Properties | Definitions |
| --- | --- |
| Distinct Option | Select Direct<br>Child if you want to select the Distinct Child Element in a list of<br>direct child elements of the looping input element, or Element XPath if you want to enter<br>an XPath to reference a different input element. |
| Distinct Child<br>Element | If you have selected the Direct child option, select the input map element<br>to be used to select distinct values. If selected, only iterations<br>of the loop that have distinct values for the selected element are<br>considered. If this is not selected, all instances of the input map<br>element are considered.<br><br>When a loop contains<br>duplicated sub-elements, the Distinct<br>Child Element field provides a filter to get<br>only one instance of each distinct sub-element. |
| Distinct<br>XPath | If you have selected the Element XPath option,<br>enter an XPath expression to evaluate the distinct elements. If the input<br>representation used is not XML, specify the representation in the<br>expression.<br><br>For example, if you want to use the<br>fn:concat function on elements named<br>a and b in a CSV representation, the<br>expression looks like this:<br>fn:concat(CSV:a,CSV:b). |
| Disable sort by distinct child | If you have specified a Distinct Child Element, select this check box to keep<br>the default sorting instead of sorting by distinct child. If this check<br>box is not selected, the output is sorted in ascending order based on<br>the value of the Distinct Child Element. |
| Emit Loop Instance If Empty | Select this check box if you want to generate a single<br>instance of this loop in the output if there are no instances of the<br>input loop. This is useful to generate loop instance with a default<br>value. |
| Stream Input | Select this check box to allow the input data for this loop<br>to be broken into chunks and processed separately. Without this<br>option, the entire input data is read into memory before the<br>transformation is executed. When Stream Input<br>is selected, since the transformation is processed in segments,<br>input data of unlimited size can be processed.<br><br>When Stream<br>Input is selected there are some significant<br>restrictions on the transformation expressions. For more<br>information, see [Streaming execution](https://help.qlik.com/talend/en-US/data-mapper-user-guide/8.0/streaming-execution). |