#### [ 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 => {
}``````
• 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`