---
title: "forloop"

doc_type: static
doc_category: static
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/docs/sline/object/forloop'
  md: 'https://developer.shopline.com/docs/sline/object/forloop.md'
---

# forloop


    Information about the current `for` loop.

    The `forloop` object is only available within the [for](https://developer.shopline.com/docs/sline/tag/for.md) tag.



## Properties

    <div>
    

        
<ObjectProperty 
    name="first"
    types={[<Mdx>boolean</Mdx>]}
>
<ObjectSummary>
Whether the current iteration is the first in the loop.
- `true`: The current iteration is the first in the loop.
- `false`: The current iteration is not the first in the loop.


</ObjectSummary>
</ObjectProperty>
        
<ObjectProperty 
    name="index"
    types={[<Mdx>integer</Mdx>]}
>
<ObjectSummary>
The 1-based index of the current iteration.


</ObjectSummary>
</ObjectProperty>
        
<ObjectProperty 
    name="index0"
    types={[<Mdx>integer</Mdx>]}
>
<ObjectSummary>
The 0-based index of the current iteration.


</ObjectSummary>
</ObjectProperty>
        
<ObjectProperty 
    name="last"
    types={[<Mdx>boolean</Mdx>]}
>
<ObjectSummary>
Whether the current iteration is the last in the loop.
- `true`: The current iteration is the last in the loop.
- `false`: The current iteration is not the last in the loop.


</ObjectSummary>
</ObjectProperty>
        
<ObjectProperty 
    name="length"
    types={[<Mdx>integer</Mdx>]}
>
<ObjectSummary>
The total number of iterations in the loop.


</ObjectSummary>
</ObjectProperty>
        
<ObjectProperty 
    name="parentloop"
    types={[<Mdx>[forloop](https://developer.shopline.com/docs/sline/object/forloop.md)</Mdx>]}
>
<ObjectSummary>
The parent `forloop` object. If the current loop is not nested within another `for` loop, `nil` is returned.


</ObjectSummary>
</ObjectProperty>
        
<ObjectProperty 
    name="rindex"
    types={[<Mdx>integer</Mdx>]}
>
<ObjectSummary>
The 1-based index of the current iteration, in reverse order.


</ObjectSummary>
</ObjectProperty>
        
<ObjectProperty 
    name="rindex0"
    types={[<Mdx>integer</Mdx>]}
>
<ObjectSummary>
The 0-based index of the current iteration, in reverse order.


</ObjectSummary>
</ObjectProperty>
        
    
    </div>



    
## Examples

        
            ### Single-level loop​

            The following example uses a single-level loop to iterate over an array and retrieves the index of the current iteration via `forloop.index`.


            

            
<SlineExample path={''} objects={ 
    [""] 
}>
```sline
{{#var arr = "one,two,three" | split(",") /}}

{{#for item in arr}}
 - {{ forloop.index }} {{ item }}
{{/for}}
```
</SlineExample>
            
        
            ### Nested loops

            The following example performs multi-level iteration within nested loops and retrieves the index of the outer (parent) iteration across levels via `forloop.parentloop.index`.


            

            
<SlineExample path={''} objects={ 
    [""] 
}>
```sline
{{#var arr1 = "one,two,three" | split(",") /}}
{{#var arr2 = "four,five,six" | split(",") /}}

{{#for item1 in arr1}}
 - parent: {{ forloop.index }} {{ item1 }}
 {{#for item2 in arr2}}
     - nested: {{ forloop.index }} {{ item2 }} parent: {{forloop.parentloop.index}}
 {{/for}}
{{/for}}
```
</SlineExample>
            
        
    
