title: Whats a good way to loop backwards in a ring buffer?
body: <p>Suppose I have a buffer:</p>
  
  <pre><code>static const int BUFFER_SIZE = 3; // for example
  int buffer[BUFFER_SIZE];
  </code></pre>
  
  <p>and I want to loop through it</p>
  
  <pre><code>int index = 0;
  for( ;; )
  {
      buffer[index] = ...;
      index = (index + 1) % BUFFER_SIZE; // index = 0, 1, 2, 0, 1, 2, 0, 1, 2, ...
  }   
  </code></pre>
  
  <p>But what happens if I want to loop through the buffer backwards?
  eg: 0, 2, 1, 0, 2, 1, ...</p>
  
  <p>Right now Im doing this:</p>
  
  <pre><code>index  = (index &lt;= 0) ? BUFFER_SIZE - 1 : index  - 1;
  </code></pre>
  
  <p>Is there a better way of doing these operations?</p>