title: Traversing INT array in two ways
body: <p>Traversing INT array in two ways is a robotic funny code (in C).</p>
  
  <p>I have an array of positions like this: <code>int pos[] = {0, 45, 90, 135, 180, 135, 90, 45};</code>
  These positions are used to move a servo motor.</p>
  
  <pre><code> 45   90   135
     \   |   /
      \  |  /
       \ | /
  0 ----------- 180
  </code></pre>
  
  <p>In main <code>loop()</code> I check distance from an obstacle, and if it's <code>&lt; xx Cm</code> my servo must rotate to next step (next array position) until it finds a free way ( <code>&gt; xx Cm</code> ).</p>
  
  <p>My main is easy:</p>
  
  <pre><code>int main (int argc, const char * argv[]) { for (;;) find(); }
  </code></pre>
  
  <p>and my core function (find) is this:</p>
  
  <pre><code>void find() {
      for ( i=0; i&lt;sizeof(pos); i++ ) // Traversing position array
      {
          distance = rand() % 7; // Simulate obstacle distance
  
          move( pos[i] );  // Simulate movements
  
          if (i==sizeof(pos)) { i=1; } // Try to reset the "i" counter. PROBLEM!
          if ( distance&lt;=5 ) continue; // Is there an obstacle?
  
          sleep(2); // Debug sleep
          find(); // Similar recursion
      }
  }
  </code></pre>
  
  <p>I don't know what is wrong in this code, but I need to move servo until is there not an obstacle.</p>
  
  <hr>
  
  <p><strong>Example</strong>:
  At position <code>90</code> I find an obstacle. I want to loop array from left to right and viceversa controlling distance every step.  If I don't find a freeway, <code>print("ko")</code> else <code>print("ok")</code>.</p>
  
  <p>How do I fix this code to work correctly?</p>