title: Skip particular (specified) iteration of for loop
body: <p>I'm pretty new to C++ but I couldn't find a workaround for this online, I feel like there might be an interesting, elegant solution possible for this.</p>
  
  <p>I'm ultimately trying to code a leapfrog algorithm for planetary motion. I've defined a class called planet</p>
  
  <pre><code>Planet(double mass, double x0, double x1, double v0, double v1)
  </code></pre>
  
  <p>and I've got an array storing information for 4 different planets:</p>
  
  <pre><code>Planet planets[] = {
  Planet(2.0, -0.5, 0, -0.94, 0.65),
  Planet(1.0, -0.6, -0.2, 1.86, 0.7),
  Planet(1.0, 0.5, 1.0, -0.44, -1.40),
  Planet(0.4, 0.6, 0.3, 1.15, -1.50)
  };
  </code></pre>
  
  <p>I'm going to want to calculate the force due to gravity of each planet on every other planet. This involves implementing the mathematical equation for the force on planet i: F_i= sum over i!=j of [(G<em>m_i</em>m_j)/r_ij], where i and j denote two planets, j being incremented each time, and r_ij the distance between the two.</p>
  
  <p>Before I start thinking about that as a whole, I was testing if I could use a for loop to select a particular planet from the array, and a particular component from that planet, and print that. That works fine via</p>
  
  <pre><code>for(int i=0; i&lt;4; ++i){
  cout &lt;&lt; planets[i].getvx() &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>However, I wanted to try exclude a particular planet, say I was computing the force on j where j=2. </p>
  
  <pre><code>for(int i=0; (i&lt;j || i&gt;j) &amp;&amp; i&lt;4; ++i){
  cout &lt;&lt; planets[i].getvx() &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>This loop terminates at 2, only printing the v0 value (as defined via the class) for p[0] and p[1], not p[3] as well as I'd have liked. Likewise, j=1 only prints v0 for p[0] and p[1]. </p>
  
  <p>Is there a convenient way to put a condition within the for loop which meets my needs or should I rethink my approach?</p>