How to condense multiple for loops with different initial values
<p>In a function, I have several consecutive for loops with the same code but different initial values for the control variable. The initial values are obtained from inputs to the function. Ie,</p>

<pre><code>void thisFunction( class A a){
  //some other code

  for (int i = a.x; i != 0; --i){
    code
  }

  for (int i = a.y; i != 0; --i){
    code
  }

  for (int i = a.z; i != 0; --i){
    code
  }

  //some other code
}
</code></pre>

<p>Is there any way to condense all the for loops into one loop so that when I make changes to the code within the loop, I won't have to change it for all three loops? An alternative is to write anotherFunction() with the initial values as input, but I need access to local variables in thisFunction().</p>

<pre><code>  void anotherFunction(int in){
      for (int i = in; i != 0; --i){
        code
      }
  }
</code></pre>

<p>So is there another way to condense the loops? </p>

<p>Thank you.</p>
