This version is out of date, covering development from v9.0.0 to v9.3.0. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v9 Icon


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]



List/Set.each(LoopVar){ action(s) }

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 LoopVar, here 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 will not 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 does not clash with existing attribute names or attribute string values of the same name that might be used as part of the data being processed.

A variable declared using var() may be altered from within the scope of an .each() loop.

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.

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.

If it is desired to iterate a list a particular number of times, another approach to the above is to use the range '...' operator which can be used to provide a numbered loop variable (see).

After each iteration of an each(){} loop, accumulated back-references are cleared. Formerly, back-references from each iteration were retained for the lifetime of the loop, making it very difficult to retrieve the desired reference.

To test for position in a loop, i.e. detecting if processing the first or last items, see List/Set.first and List/Set.last.

A worked example of looping is here.

Examples of using action() within a loop to create attribute references is given here.