LassoScript Utility
Basics Browse Detail

[Iterate] ... [/Iterate]

Tag Link [Iterate] ... Category Conditional
Type Container Source Available No
Support Preferred Version 6.0
Change Unchanged Data Source Any
Output Type None Security Tag
Implementation Internal Sets Lasso 8.5, Lasso 8.0, Lasso 7.0, Lasso 6.0

Description

The [Iterate] ... [/Iterate] tags loop through each element of a complex data type such as an array or a map. A variable is set to the value of each element of the complex data type in turn. This allows the same operation to be performed on each element.

The first parameter to the opening [Iterate] tag should be the complex data type which is to be iterated through. The second parameter should be a reference to a variable that will be set to each item in turn. The second parameter is usually specified as (Variable: 'Variable Name').

The [Iterate] ... [/Iterate] tags can be used on any data type that supports the [...->Get] and [...->Size] parameters including maps, pairs, arrays, and strings. Custom data types are also supported providing they support the required member tags.

Note: The [Iterate] ... [/Iterate] tags can be used rather than performing a [Loop] ... [/Loop] on the size of an array and then [Array->Get] to fetch each particular item.

Syntax

[Iterate: Array, (Variable: 'Item')]
... [Variable: 'Item'] ...
[/Iterate]

[Iterate: Map, (Variable: 'Item')]
... [Variable: 'Item'] ...
[/Iterate]

[Iterate: 'String', (Variable: 'Char')]
... [Variable: 'Char'] ...
[/Iterate]

Parameters

Required Parameters
Complex Data Type The first parameter is a complex data type that is to be iterated through.
Variable Reference The second parameter is a reference to a variable which will be set to the value of each element of the complex data type in turn. Usually of the form (Variable: 'Variable Name')

Examples

To iterate through an array:

Use the [Iterate] ... [/Iterate] tags. In the following example each element of an array is output on a separate line. The opening [Iterate] tag contains the name of the variable that contains the array and a variable definition which will be set to each element of the array in turn.

[Variable: 'myArray' = (Array: 'Red', 'Blue', 'Green')]
[Iterate: $myArray, (Variable: 'temp')]
<br>[Output: $temp]
[/Iterate]

<br>Red
<br>Blue
<br>Green