Logo

Programming-Idioms

  • PHP
  • C++
#include <ranges>
auto s = std::ranges::fold_left(x, 0, std::plus<int>{});
#include <functional>
#include <numeric>
int s = std::accumulate(x.begin(), x.end(), 0, std::plus<int>());

std::plus<int>() parameter optional (defaults to this if not provided)
$s = array_sum($x);
for E of x loop
   S := S + E;
end loop;

x is an array.
S is initialized to be 0.

New implementation...
< >
deleplace