# `effect.call_in_loop`

Outside call inside a `for` loop.

Area 3, [Logic](../topics/logic.md); not declinable; the next step is usually the agent's.

An action's outside calls lie along a way through it whose length is known
before it runs, so a loop of them is `batches.each`:




```jadpo
use app { sheets }
use bakery/types { SheetText }
use bakery/failures { SheetNotKept }

/// Keeps each price sheet a supplier sent, one call for each.
action keep_sheets(sheet_texts: List<SheetText>) fails SheetNotKept -> List<File> {
    var mut kept: List<File> = []
    for sheet_text in sheet_texts {
        var sheet: File = attempt sheets.put(encoding.to_utf8(sheet_text), FileType.csv) {
            storage_full: SheetNotKept
        }
        kept = list.append(kept, sheet)
    }
    return kept
}
```

```text
error: `sheets.put` is called once for every item of the loop
 --> domains/bakery/actions/keep_sheets.jadpo:9:35
  |
9 |         var sheet: File = attempt sheets.put(encoding.to_utf8(sheet_text), FileType.csv) {
  |                                   ^^^^^^^^^^ inside `for`
  reason: An action's outside calls lie along a way through it whose length is known before it runs, so a retry can replay them in order; a loop makes one for each item. A provider that takes a list is called once with the list.
  next: Make the calls one item at a time with `batches.each` (agent)
  rule: effect.call_in_loop
  help: https://jadpo.dev/docs/errors/effect.call_in_loop

check failed: 1 error, 4 files
```
