Answers.Body: <p>While your conditional is complete personally preference I would do the following as I find it slightly easier to read. Note the use of the <code>{%- if -%}</code> to trim <a href="http://twig.sensiolabs.org/doc/templates.html#whitespace-control">whitespace</a>:</p>
  
  <pre><code>{% for category in entry.mediaType %}
      &lt;b&gt;{{ category.title }}&lt;/b&gt;
      {%- if not loop.last -%}
        ,
      {% endif %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-04T05:18:37.447Z
Answers.Text: To clean it up even further: `{{ not loop.last ? "," }}`
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-07T09:30:25.497Z
Answers.Text: @LindseyD Your suggestion seems very neat but why do I get `unexpected char '?'` ?
Answers.UserDisplayName: Pranasas
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-07T14:16:08.420Z
Answers.Text: @Pranasas I don’t know. I suggest starting a new thread, since this one is over 3 years old. Feel free to link back to this thread (or answer) for reference.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-04T04:17:50.333Z
Answers.LastActivityDate: 2014-10-04T04:17:50.333Z
Answers.UserDisplayName: jnowland
Answers.Body: <pre><code>{% for category in entry.mediaType %}
      &lt;b&gt;{{ category.title }}&lt;/b&gt;{{ "," if not loop.last }}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-11T09:56:02.003Z
Answers.LastActivityDate: 2019-02-27T06:33:47.363Z
Answers.LastEditDate: 2019-02-27T06:33:47.363Z
Answers.UserDisplayName: Chuanwen Chen
Answers.Body: <p>There is a special tag inside for loops you can use for this</p>
  
  <pre><code>{% for category in entry.mediaType %}
      &lt;b&gt;{{ category.title }}&lt;/b&gt;,
      {% if loop.last %}
          &lt;b&gt;{{ category.title }}&lt;/b&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>Full list <a href="https://gist.github.com/brandonkelly/8584132#craft-2" rel="noreferrer">here</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-03T16:31:11.917Z
Answers.Text: Awesome, I could not find this anywhere in the Craft docs, thank you!
Answers.UserDisplayName: Matt Wilcox
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-03T17:10:29.200Z
Answers.Text: You didn't find it in the Craft docs because [it's a native Twig variable](http://twig.sensiolabs.org/doc/tags/for.html#the-loop-variable).
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-04T03:57:36.047Z
Answers.Text: Is there an advantage to this vs wrapping the "," in a `{% if not loop.last %}`?
Answers.UserDisplayName: Dustin Walker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-04T04:12:52.533Z
Answers.Text: Personal preference.
Answers.UserDisplayName: jnowland
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-03T16:25:39.250Z
Answers.LastActivityDate: 2014-10-03T16:25:39.250Z
Answers.UserDisplayName: Seán O'Grady
Body: <p>I want to create a comma separated list of categories to which an entry belongs, but without the trailing slash on the last element... can't work out how to remove it!</p>
  
  <pre><code>{% for category in entry.mediaType %}
      &lt;b&gt;{{ category.title }}&lt;/b&gt;,
  {% endfor %}
  </code></pre>
  
Tags: <loop>
Title: Remove trailing comma from an output loop?
ThreadText: # Remove trailing comma from an output loop?
  
  (Asked by: username_0 on 2014-10-03)
  
  I want to create a comma separated list of categories to which an entry belongs, but without the trailing slash on the last element... can't work out how to remove it!
  
  ```
  {% for category in entry.mediaType %}
      <b>{{ category.title }}</b>,
  {% endfor %}
  
  ```
  
  **Tags:** loop
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_5 on 2014-10-03. Score: 15 | Accepted answer
  
  There is a special tag inside for loops you can use for this
  
  ```
  {% for category in entry.mediaType %}
      <b>{{ category.title }}</b>,
      {% if loop.last %}
          <b>{{ category.title }}</b>
      {% endif %}
  {% endfor %}
  
  ```
  
  Full list [here](https://gist.github.com/brandonkelly/8584132#craft-2)
  
  > **Comments:**
  > **username_0**: Awesome, I could not find this anywhere in the Craft docs, thank you!  
  > **username_2**: You didn't find it in the Craft docs because [it's a native Twig variable](http://twig.sensiolabs.org/doc/tags/for.html#the-loop-variable).  
  > **username_6**: Is there an advantage to this vs wrapping the "," in a `{% if not loop.last %}`?  
  > **username_1**: Personal preference.  
  
  ---
  
  ### Answer by username_1 on 2014-10-04. Score: 17
  
  While your conditional is complete personally preference I would do the following as I find it slightly easier to read. Note the use of the `{%- if -%}` to trim [whitespace](http://twig.sensiolabs.org/doc/templates.html#whitespace-control):
  
  ```
  {% for category in entry.mediaType %}
      <b>{{ category.title }}</b>
      {%- if not loop.last -%}
        ,
      {% endif %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_2**: To clean it up even further: `{{ not loop.last ? "," }}`  
  > **username_3**: @username_2 Your suggestion seems very neat but why do I get `unexpected char '?'` ?  
  > **username_2**: @username_3 I don’t know. I suggest starting a new thread, since this one is over 3 years old. Feel free to link back to this thread (or answer) for reference.  
  
  ---
  
  ### Answer by username_4 on 2018-12-11. Score: 5
  
  ```
  {% for category in entry.mediaType %}
      <b>{{ category.title }}</b>{{ "," if not loop.last }}
  {% endfor %}
  
  ```
  
  
  ---
  
  