# Reading in a loop

A query or `Todo.get` inside a `for` loop is a compile error, because it
would read once per item. Read the whole set with one query using `in`
instead:

```jadpo
// domains/planning/queries/todos_by_ids.jadpo
query todos_by_ids(todo_ids: List<Todo.id>) -> List<TodoView> {
    from: Todo
    where: Todo.id in todo_ids
    order: [Todo.created_at asc]
    limit: 100
}
```

Writes inside a loop are allowed: the list is bounded, and every write
joins the action's transaction.

An outside call inside a loop isn't allowed ([Loops](loops.md)).
A loop of calls is `batches.each`
([How a run is kept](how-a-run-is-kept.md)). A batch
that should keep its partial progress is a schedule or subscriber
handling one item per action.
