title: Looping through an array using ColdFusion
body: <p>I have a shopping cart array, which has a variable to tell me if the product is an accessory or not, this will be either yes or no. I need to loop through the cart and find out the following:</p>
  
  <ul>
  <li>If the cart contains accessories only; do whatever.</li>
  <li>If the cart is products only; do whatever.</li>
  <li>If the cart has products and accessories; do whatever.</li>
  </ul>
  
  <p>I have been trying this:</p>
  
  <pre><code>&lt;cfloop index="i" from="1" to="#arrayLen(session.mycart)#"&gt;
    &lt;cfif session.mycart[i].accs EQ "yes"&gt;
      &lt;cfset accPresent = "yes"&gt;
    &lt;/cfif&gt;
    &lt;cfif session.mycart[i].accs EQ "no"&gt;
      &lt;cfset prodpresent = "yes"&gt;
    &lt;/cfif&gt;
  &lt;/cfloop&gt;
  
  &lt;cfif accPresent EQ "yes" and prodPresent EQ "no"&gt;
    &lt;cfset  bothPresent EQ "yes"&gt;
  &lt;/cfif&gt;
  </code></pre>
  
  <p>This falls down as accPresent is not found, this i think is due to the fact the loop goes through one at a time and the accs is not equal to yes once it find a non accessory product. What's the best way to achieve what I'm trying to do?</p>