# List iteration in Jira Automation: syntax and examples

URL: https://goingstellar.ro/reference/smart-values/list-iteration/

A block that opens with a list name and closes with {{/}} repeats its content once per item. Inside the block you can read the item's own properties, print the item itself with a dot, and use first, last and index to control separators and prefixes.

## Syntax

```
{{#list}}...{{/}}
{{#list}}{{.}}{{^last}}, {{/}}{{/}}
{{#list}}{{#first}}...{{/}}{{/}}
{{#list}}{{index}}{{/}}
```

## Arguments

- `first / last` (required: no): Inside the loop, {{#first}} runs only for the first item and {{#last}} only for the last. {{^first}} and {{^last}} run for every other item.
- `index` (required: no): The position of the current item, counted from 0.
- `.` (required: no): The current item itself, used when the list holds plain values such as labels.

## Works on

- Fields: any list, such as issue.labels, issue.comments or the result of split().
- Returns: the text of the block, repeated once per item.

## Examples

```
{{#issue.labels}}{{.}}, {{/}}
```

Print every label. A separator written inside the block also lands after the last item.

Result:

```
checkout, demo, 
```

Run on Jira Cloud on 29 Nov 2026.

```
{{#issue.labels}}{{.}}{{^last}}, {{/}}{{/}}
```

Print the labels as a clean comma list by skipping the separator after the last item.

Result:

```
checkout, demo
```

Run on Jira Cloud on 29 Nov 2026.

```
{{#issue.labels}}option-{{.}}{{^last}},{{/}}{{/}}
```

Turn labels into option values for a field or an outgoing request, with a prefix and no trailing comma.

Result:

```
option-checkout,option-demo
```

Run on Jira Cloud on 29 Nov 2026.

```
{{#issue.comments}}{{index}}. {{body}}{{^last}},{{/}}{{/}}
```

Number the comments of a work item in one line. The first item has index 0.

Result:

```
0. First comment from QA,1. Second comment: fixed in build 42
```

Run on Jira Cloud on 29 Nov 2026.

```
{{#issue.labels}}{{#first}}primary: {{/}}{{.}}{{^last}}, {{/}}{{/}}
```

Mark the first label as the primary one and still separate the rest with commas.

Result:

```
primary: checkout, demo
```

Run on Jira Cloud on 29 Nov 2026.

```
{{#issue.summary.split(" ")}}[{{.}}]{{/}}
```

Chain a text function with a loop: wrap every word of the summary in brackets.

Result:

```
[Hello][World!]
```

Run on Jira Cloud on 29 Nov 2026.

## Where the documentation differs

- `{{#issue.comments}}{{#last}}Last: {{/}}{{body}}{{/}}`: run on Jira Cloud, 29 Nov 2026: the documentation says `Places "Last:" in front of the first comment.`, the actual result is `First comment from QALast: Second comment: fixed in build 42`.

## Pitfalls

- The Atlassian text says `{{#last}}Last: {{/}}` goes in front of the first comment. The prefix lands in front of the last comment, which is what a block named last should do (checked on Jira Cloud, November 2026).
- Labels are plain text values, so the loop needs `{{.}}`. `{{name}}` inside a label loop renders an empty string.
- A separator inside the loop appears after every item, the last one included. Put it in `{{^last}}...{{/}}`, or use join() when you only need a separated list.
- Nothing is added between items on its own: comment bodies printed in a loop run together unless the block ends with a space, a comma or a line break.

## Questions and answers

### Does the index start at 0 or at 1?

At 0. With two comments, `{{#issue.comments}}{{index}}{{/}}` prints 01.

## Related

- [join()](https://goingstellar.ro/reference/smart-values/list-join/)
- [first, last, get(), getFromEnd()](https://goingstellar.ro/reference/smart-values/list-first-last-get/)
- [size and isEmpty on lists](https://goingstellar.ro/reference/smart-values/list-size-isempty/)
- [split()](https://goingstellar.ro/reference/smart-values/split/)
- [{{issue.comments}}](https://goingstellar.ro/reference/smart-values/issue-comments/)

## Sources

- [Jira smart values: lists (Atlassian Support)](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/)

