The generic looping construct over a list in DAML is `foldl`

. You can think of it as walking down the list from left to right and, on each element, doing some operation while carrying over the result. The general form is:

```
foldl function_on_each_element initial_value list
```

where `function_on_each_element`

is a function of two arguments, the accumulated value so far and the new element weâ€™re considering, and must return the new accumulated value. This raises the question of what the â€śaccumulated value so farâ€ť is when considering the first element, and that is precisely what the `initial_value`

is there for. The final return value of `foldl`

is the accumulated value after processing the last element.

In your case, this means youâ€™d have:

```
foldl (\soFar newElem -> soFar + newElem) 0 quantityList
```

where `\soFar newElem -> soFar + newElem`

is a function that represents what to do on each step (`quantity => do a = a + quantity`

) and `0`

is the initial value (`Let a = 0`

).

Note that in this case we can use a syntactic trick to make this shorter. This is completely optional and up to you whether you think this makes your code better. Here is the trick. First, variable names in a function donâ€™t really matter outside of it, so `\soFar newElem -> soFar + newElem`

is really the same as `\a b -> a + b`

. This is really just addition, though. In DAML, a binary operator like `+`

can be turned into a function by wrapping it in parentheses, so `(+)`

is exactly the same as `\a b -> a + b`

. This means we can also write:

```
foldl (+) 0 quantityList
```

Finally, for this case the standard library also happens to have a builtin function to directly do what you want: `sum quantityList`

.