This version is out of date, covering development from v8.0.0 to v8.x.x. 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 v8 Icon

List/Set.each(LoopVar)


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]

 Baseline

 


List/Set.each(LoopVar)

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.

A worked example of looping is here.

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