title: How to convert for loop into streams?
body: <p>How would I use streams to achieve the same result as below? I am trying to find the average of this 'tot' value by first iterating through TickQueue (a queue implementation) and summing tot, and then afterwards dividing by the counter value to find the average.</p>
  <pre><code>int counter = 0;
  double tot = 0;
  
  for (Tick t: TickQueue)
  {
      if ((t.getAskPrice() == 0 &amp;&amp; t.getBidPrice() == 0) || (t.getAskPrice() == 0) || (t.getBidPrice() == 0))
      {
          tot += 0;
      }
      else
      {
          tot += (t.getAskPrice() - t.getBidPrice());
          counter++;
      }
  }
  
  double avg = tot/counter;
  </code></pre>