This version is out of date, covering development from v5.0.0 to v5.12.2. It is maintained here only for inbound reference links from elsewhere.

Jump to the current version of aTbRef.

Tinderbox Icon

List/Set.each()


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Function   [other Function type actions]

 Item   [operators of similar scope]

 Data manipulation   [other Data manipulation operators]

 5.10.0

 5.10.2


List/Set.each()

This allows you to operate in turn on each item in a list or set.

$MyList.each(x){ $Result=$Result +x+"\n" ; } 

will replace the text of the note with a list of values of $MyList, each on its own line. The in-loop variable 'x' is simply the string defined in .each(), and is case-sensitive and a '$' prefix is not required for in-loop references to the loop variable.

Thus .each(LoopVar) would iterate using references to 'LoopVar', .each(Y) would iterate using references to 'Y', and so forth. Consider making the loop variable something clear to both the user and to Tinderbox. In the trivial example above, 'x' seems pretty clear but might be misread by the users - in a mathematical context - as a multiplication symbol; Tinderbox won't be confused as it uses * for multiplication but consider how something like 'LoopVar' might be clearer. By the same token make sure the loop variable name doesn't clash with existing attribute names or attribute string values of the same name that might be used as part of the data being processed.

If $Total is a numeric attribute and $MyList is a list of numbers

$Total=0; $MyList.each(n){$Total=$Total+n*n;}

computes the sum of the squares of the values in $MyList.

From v5.10.2, the LoopVar can be a path and this be used as a variable designator for attribute offset references inside the loop:

$Text=""; collect($Overdue,$Path).each(x){ 
	$Text = $Text+":"+$Text(x);
}

In the above, 'x' is a $Path value and is being used to provide the offset reference in the loop.

A worked example of looping is here.


Possible relevant notes (via "Similar Notes" feature):


A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Functional Types : Function actions : List/Set.each()