Lasso Soft Inc. > Home

[ delve->foreach ]

Method

The [delve->foreach] method invokes a capture block on each element in the delve. The method requires a capture block to be passed to it. The capture block is invoked on each element of the delve in turn (i.e. the capture block is invoked with each element of the delve). The current value in the delve can be accessed using the #1 variable.

  • Syntax
#myDelve->forEach => {
}
Examples
  • Beginner

Sum delve

This example calculates the sum of each item in the delve. The sum is output.

Code

local( total = 0 );
local( arr = array( 1, 2, (: 3, 4, 5 ), list( 6, 7 ), array( 8, 9 ) ) );

delve( #arr )->forEach => {
	#total += #1;
} // Close forEach

#total;

Result

45

Sum delve

This example calculates the sum of each item in the delve. The sum is output.

Code

local( total = 0 );
local( arr = array( 1, 2, (: 3, 4, 5 ), list( 6, 7 ), array( 8, 9 ) ) );

delve( #arr )->forEach => {
	#total += #1;
} // Close forEach

#total;

Result

45

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