Answers.Body: <p>I think it'll be easier and more efficient to achieve that if you use the loop functionality instead of querying the actual tags. I think this code does what you want:</p>
  
  <pre><code>{% set topics = '' %}
  
  {% for topic in entry.topics %}
      {% set topics = topics ~ topic ~ (loop.index &lt; loop.length-1 ? ', ' : loop.index &lt; loop.length ? ' and ') %}
  {% endfor %}
  
  &lt;p&gt;This is a sentence with {{ topics }}.&lt;/p&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-14T18:25:54.370Z
Answers.Text: You can also use `loop.last` to trim that logic down even further.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-14T13:09:59.990Z
Answers.LastActivityDate: 2014-09-14T13:09:59.990Z
Answers.UserDisplayName: André Elvan
Body: <p>I try to build a complete sentence based on tags as follows:</p>
  
  <p><strong>This is a sentence with tag1, tag2 and tag3.</strong></p>
  
  <p>My code is:</p>
  
  <pre><code>{% set topics = entry.topics.first %}
  
  {% for topic in entry.topics.offset(1) %}
      {% if topic != entry.topics.last %}
         {% set topics = topics ~ ', ' ~ topic %}
      {% endif %}
  {% endfor %}
  
  &lt;p&gt;This is a sentence with {{ topics }} and {{ entry.topics.last }}.&lt;/p&gt;
  </code></pre>
  
  <p>My problem is that the if clause does not work. The results is always:</p>
  
  <p><strong>This is a sentence with tag1, tag2, tag3 and tag3.</strong></p>
  
Tags: <tags><array>
Title: How to build a sentence based on tags
ThreadText: # How to build a sentence based on tags
  
  (Asked by: username_0 on 2014-09-14)
  
  I try to build a complete sentence based on tags as follows:
  
  **This is a sentence with tag1, tag2 and tag3.**
  
  My code is:
  
  ```
  {% set topics = entry.topics.first %}
  
  {% for topic in entry.topics.offset(1) %}
      {% if topic != entry.topics.last %}
         {% set topics = topics ~ ', ' ~ topic %}
      {% endif %}
  {% endfor %}
  
  <p>This is a sentence with {{ topics }} and {{ entry.topics.last }}.</p>
  
  ```
  
  My problem is that the if clause does not work. The results is always:
  
  **This is a sentence with tag1, tag2, tag3 and tag3.**
  
  **Tags:** tags, array
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-09-14. Score: 5 | Accepted answer
  
  I think it'll be easier and more efficient to achieve that if you use the loop functionality instead of querying the actual tags. I think this code does what you want:
  
  ```
  {% set topics = '' %}
  
  {% for topic in entry.topics %}
      {% set topics = topics ~ topic ~ (loop.index < loop.length-1 ? ', ' : loop.index < loop.length ? ' and ') %}
  {% endfor %}
  
  <p>This is a sentence with {{ topics }}.</p>
  
  ```
  
  > **Comments:**
  > **username_2**: You can also use `loop.last` to trim that logic down even further.  
  
  ---
  
  