Lasso Soft Inc. > Home

[ set->forEach ]

Method

The [set->forEach] method allows an operation to be performed on each element of the set in turn.

  • Syntax
set->forEach => {^  ^}
Examples
  • Beginner

Perform an action on each element in a set

This example uses the [set->forEach] method to output a list of squares of each number in a set.
 

Code

define squareMe(n::integer=1) => {  
    return #n * #n 
}

var( aSet = array(1, 2, 3, 5, 8, 13))

$aSet->forEach => {^  squareMe(#1)+'  ' ^}

Result

1  4  9  25  64  169  

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft