title: Storing loop values into variable and use it outside of it
body: <p>I'm trying to understand how to store data from a loop in a variable and use it outside.</p>
  
  <p>As a code example, i have a string in a variable declared outside the foreach loop which is an array created by the Split method:</p>
  
  <pre><code>var features = @GetString(fieldValue);
  List&lt;string&gt; optionValues = new List&lt;string&gt;();
  
  foreach(var option in customField.Options)
  {
     optionValues.Add(option.customField.Options.Name);
  }             
  
  features = string.Join(';', optionValues);
  
  foreach(var str in features.Split(';'))
  {
      features = str;
  }
  </code></pre>
  
  <p>I want to render the string features in a helper function outside of it like this:</p>
  
  <pre><code>@RenderFieldValue(features)
  </code></pre>
  
  <p>The helper receives a string parameter:</p>
  
  <pre><code>@helper RenderFieldValue(string value)
  {
      &lt;div&gt;@value&lt;/div&gt;
  }
  </code></pre>
  
  <p>The problem is that i'm only outputting "part4" which is the last part of the string. I'm trying to understand how programming works in relation to storing values from a loop and use all of them outside of it.
  It should output this:</p>
  
  <pre><code>part1
  part2
  part3
  part4
  </code></pre>