# `Otera.Loop`
[🔗](https://github.com/georgeguimaraes/otera/blob/v0.1.0/lib/otera/loop.ex#L1)

The `loop` variable inside a `{% for %}` block, like the `LoopContext` of Jinja2.

It has `index`, `index0`, `revindex`, `revindex0`, `first`, `last`, `length`, `depth`, `depth0`, `previtem` and `nextitem`, the methods `cycle` and `changed`, and for a recursive loop it can be called with the items of the next level.

Each iteration gets a new `Loop` with the same `ref`. `changed` keeps its last value for the `ref` in `Otera.State`.

# `changed?`

```elixir
@spec changed?(
  %Otera.Loop{
    depth0: term(),
    index0: term(),
    items: term(),
    recurse: term(),
    ref: term()
  },
  list()
) :: boolean()
```

Returns true when `values` differ from the values of the previous call in this loop, like `loop.changed(*values)`.

# `get`

```elixir
@spec get(
  %Otera.Loop{
    depth0: term(),
    index0: term(),
    items: term(),
    recurse: term(),
    ref: term()
  },
  String.t()
) :: term()
```

Returns the attribute `name` of `loop`.

# `remaining`

```elixir
@spec remaining(%Otera.Loop{
  depth0: term(),
  index0: term(),
  items: term(),
  recurse: term(),
  ref: term()
}) :: [
  {term(),
   %Otera.Loop{
     depth0: term(),
     index0: term(),
     items: term(),
     recurse: term(),
     ref: term()
   }}
]
```

Returns the items after the current one as `{item, loop}` pairs, which Python gives when a template iterates over the loop.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
