title: Accumulating values from a listbox with a for loop instead of if statements
body: <p>I have learned how to accumulate totals with if statements and now I am trying to shorten up my code. 
  A friend of mine told me that you can use a FOR loop to do this so I tried it out but I am having trouble understanding FOR loops completely. </p>
  
  <p>My <code>IF</code> Code is this... </p>
  
  <pre><code>if (lbSnacks.Items[0].Selected)
  {
      decSnackSaleTotal = decSnackSaleTotal + Convert.ToDecimal(lbSnacks.Items[0].Value);
  }
  if (lbSnacks.Items[1].Selected)
  {
     decSnackSaleTotal = decSnackSaleTotal + Convert.ToDecimal(lbSnacks.Items[1].Value);
  }
  if (lbSnacks.Items[2].Selected)
  {
      decSnackSaleTotal = decSnackSaleTotal + Convert.ToDecimal(lbSnacks.Items[2].Value);
  }
  if (lbSnacks.Items[3].Selected)
  {
       decSnackSaleTotal = decSnackSaleTotal + Convert.ToDecimal(lbSnacks.Items[3].Value);
  }
  if (lbSnacks.Items[4].Selected)
  {
       decSnackSaleTotal = decSnackSaleTotal + Convert.ToDecimal(lbSnacks.Items[4].Value);
  }
  if (lbSnacks.Items[5].Selected)
  {
       decSnackSaleTotal = decSnackSaleTotal + Convert.ToDecimal(lbSnacks.Items[5].Value);
  }
  </code></pre>
  
  <p>Of course, I commented it out to try to use the for loop. 
  The loop I used is this: </p>
  
  <pre><code>for (int i = 0; i &lt; lbSelected.Items.Count; i++)
  {
     decSnackSaleTotal += Convert.ToDecimal(lbSelected.Items[i]); 
  }
  </code></pre>
  
  <p><code>lbSelected</code> is my second <code>listbox</code> where the selected items go from the customer. 
  <code>lbSnacks</code> is my first <code>listbox</code> where the snack selection is. </p>
  
  <p>Thanks! </p>