title: Powershell Comparing Array Elements
body: <p>I'm likely missing something simple here, so I apologize in advance.  I am also aware that there is likely a better approach to this, so I'm open to that as well.</p>
  
  <p>I'm trying to run a PowerShell script that will look at an array of values, comparing them to see the value of the difference between two elements of an array.</p>
  
  <p>Below is a sample data set I'm using to test with that is imported into powershell from CSV:</p>
  
  <pre>1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.7, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.7, 2.9, 3.0</pre>
  
  <p>What I'm trying to accomplish is running through this list and comparing the second entry with the first, the third with the second, fourth with the third, etc, adding the element to <code>$export</code> ONLY if it has a value that is at least 0.2 greater than the previous element.</p>
  
  <p>Here's what I've tried:</p>
  
  <pre><code>$import = get-content C:/pathtoCSVfile
  $count = $import.Length-1;
  $current=0;
  
  Do 
  {    
      $current=$current+1;
      $previous=$current-1
  
      if (($import[$current]-$import[$previous]) -ge 0.2)
      {
          $export=$export+$import[$current]+"`r`n";
      }
  } 
  until ($current -eq $count)
  </code></pre>
  
  <p>Now I've run this with Trace on and it assigns values to <code>$current</code> and <code>$previous</code> and runs the subtraction of the two as described in the <code>if</code> condition on each loop through, but ONLY for the value of 2.7 (<code>$import[14]-$import[13]</code>) is it registering that the if condition has been met, thus leaving only a single value of 2.7 in <code>$export</code>.  I expected other values (1.7, 1.9, and 2.9) to also be added to the <code>$export</code> variable.  </p>
  
  <p>Again, this is probably something stupid/obvious I'm overlooking, but I can't seem to figure it out.  Thanks in advance for any insight you can offer.</p>