Lambda - Incrementing a variable in a loop

Options
Mr_English
Mr_English Member
edited October 2023 in ? Transforming data

I have an int variable called count_emails.

I wanted to use it as a counter by incrementing it in a foreach loop. I thought a simple example like this would be a good way to start with lambdas.

I tried both of the following, but the value of count_emails remains 1. - see screenshot 2

return $var.count_emails++;
return $var.count_emails = $var.count_emails + 1;

Screenshot 1 shows the code.

Is it possible to create a counter like this? Or have I got the wrong idea?

Screenshot 1

Screenshot 2

Best Answer

Answers