# forloop

> forloop Liquid 对象：在 Shoplazza Theme 中暴露所在 for 循环的状态，例如当前序号和是否为最后一次循环。

父级 [for loop](../tags/iteration#for) 的信息。

| Properties | Type    | Description                                                                   |
| :--------- | :------ | :---------------------------------------------------------------------------- |
| `first`    | boolean | 若当前迭代为第一次，则返回 `true`；否则返回 `false`。 |
| `last`     | boolean | 若当前迭代为最后一次，则返回 `true`；否则返回 `false`。  |
| `index`    | number  | 当前迭代的从 1 开始的索引。                                   |
| `index0`   | number  | 当前迭代的从 0 开始的索引。                                   |
| `length`   | number  | 循环中的迭代总次数。                                   |
| `rindex`   | number  | 当前迭代的从 1 开始的逆序索引。                 |
| `rindex0`  | number  | 当前迭代的从 0 开始的逆序索引。                 |

```json title="对象"
{
  "first":true,
  "last":false,
  "index":1,
  "index0":0,
  "rindex":4,
  "rindex0":3,
  "length":4
}
```

**使用 `forloop` object**

```liquid title="代码"
{% for i in (1..5) %}
  {% if forloop.length > 0 %}
    {{ i }}{% unless forloop.last %},{% endunless %}
  {% endif %}
{% endfor %}
```

```html title="输出"
1, 2, 3, 4, 5
```
