Answers.Body: <p>Your dump from outside the loop is being dumped BEFORE the variable is set within the loop. Move it to after the loop and try it again.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-02T21:03:10.237Z
Answers.Text: Rick, that makes total sense, and I can't believe I missed that. Thank you! :)
Answers.UserDisplayName: Angela
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-02T21:05:21.163Z
Answers.Text: It's the simple things that trip us all up.
Answers.UserDisplayName: Rick
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-02T21:06:31.593Z
Answers.Text: Ha - exactly! :)
Answers.UserDisplayName: Angela
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-02T20:56:44.377Z
Answers.LastActivityDate: 2015-09-02T20:56:44.377Z
Answers.UserDisplayName: Rick
Answers.Body: <p>The output looks like what I'd expect it to be based on the code sample.</p>
  
  <p>You're saying that if you put:</p>
  
  <pre><code> Excluded Expenses (After Loop): {{ excludedExpenses }}
  </code></pre>
  
  <p>...AFTER the end of the loop, it doesn't display 'Pets'?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-02T21:00:18.703Z
Answers.LastActivityDate: 2015-09-02T21:00:18.703Z
Answers.UserDisplayName: andrew.welch
Body: <p>I've read that you can set a variable inside of a loop, and set that same variable outside of the loop with "" to be able to use it outside of the loop. Although when attempting this, it is not working for me. Here is the code I am using (simplified for the purpose of troubleshooting):</p>
  
  <pre><code>{% requireLogin %}
  
  {% if currentUser == user.username %}
  
  {# -- Set Excludes Expenses here as well, to use out of the loop -- #}
  {% set excludedExpenses = "" %}
  
      Excluded Expenses (Outside Loop): {{ excludedExpenses }}&lt;br /&gt;
  
      &lt;p&gt;{{ dump(excludedExpenses) }}&lt;/p&gt;
  
      {# -- Get All Expense Entries -- #}
      {% set userExpenses = craft.entries.section('expenses').authorId(currentUser.id).limit(null) %}
  
          {# --- Excluded Expenses Loop -- #}
          {% for expense in userExpenses if expense.excludeExpense.contains('Temporarily Exclude') %}
              {% set excludedExpenses = expense.expenseName %}
  
              Excluded Expenses (Inside Loop): {{ excludedExpenses }}
  
              &lt;p&gt;{{ dump(excludedExpenses) }}&lt;/p&gt; 
  
          {% endfor %}
          {# -- End Excluded Expenses Loop -- #}  
  
  {% endif %}
  </code></pre>
  
  <p>This is the result - <a href="http://cl.ly/image/1Z2Q2r2Q102s" rel="nofollow">http://cl.ly/image/1Z2Q2r2Q102s</a></p>
  
  <p>The variable is only being recognized and displayed inside of the loop. The actual variable I will use (beyond this simple test) is an integer. I tested with an integer variable and that failed also, so I am not sure if that would change anything for this example. Thanks in advance for any help you can give! :)</p>
  
Tags: <variable><loop>
Title: Variable Not Available Outside of Loop
ThreadText: # Variable Not Available Outside of Loop
  
  (Asked by: username_0 on 2015-09-02)
  
  I've read that you can set a variable inside of a loop, and set that same variable outside of the loop with "" to be able to use it outside of the loop. Although when attempting this, it is not working for me. Here is the code I am using (simplified for the purpose of troubleshooting):
  
  ```
  {% requireLogin %}
  
  {% if currentUser == user.username %}
  
  {# -- Set Excludes Expenses here as well, to use out of the loop -- #}
  {% set excludedExpenses = "" %}
  
      Excluded Expenses (Outside Loop): {{ excludedExpenses }}<br />
  
      <p>{{ dump(excludedExpenses) }}</p>
  
      {# -- Get All Expense Entries -- #}
      {% set userExpenses = craft.entries.section('expenses').authorId(currentUser.id).limit(null) %}
  
          {# --- Excluded Expenses Loop -- #}
          {% for expense in userExpenses if expense.excludeExpense.contains('Temporarily Exclude') %}
              {% set excludedExpenses = expense.expenseName %}
  
              Excluded Expenses (Inside Loop): {{ excludedExpenses }}
  
              <p>{{ dump(excludedExpenses) }}</p> 
  
          {% endfor %}
          {# -- End Excluded Expenses Loop -- #}  
  
  {% endif %}
  
  ```
  
  This is the result - <http://cl.ly/image/1Z2Q2r2Q102s>
  
  The variable is only being recognized and displayed inside of the loop. The actual variable I will use (beyond this simple test) is an integer. I tested with an integer variable and that failed also, so I am not sure if that would change anything for this example. Thanks in advance for any help you can give! :)
  
  **Tags:** variable, loop
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-09-02. Score: 3 | Accepted answer
  
  Your dump from outside the loop is being dumped BEFORE the variable is set within the loop. Move it to after the loop and try it again.
  
  > **Comments:**
  > **username_0**: username_1, that makes total sense, and I can't believe I missed that. Thank you! :)  
  > **username_1**: It's the simple things that trip us all up.  
  > **username_0**: Ha - exactly! :)  
  
  ---
  
  ### Answer by username_2 on 2015-09-02. Score: 1
  
  The output looks like what I'd expect it to be based on the code sample.
  
  You're saying that if you put:
  
  ```
   Excluded Expenses (After Loop): {{ excludedExpenses }}
  
  ```
  
  ...AFTER the end of the loop, it doesn't display 'Pets'?
  
  
  ---
  
  