title: How Can I Use Parallel For in TPL instead of While
body: <p>I want to use parallel for in a statement instead of while statement. When i look at samples Parallel For runs with only a known -or variable- count.</p>
  
  <p>But i don't know how many times my loop will run, and its unable to link it to a variable in run time.</p>
  
  <p>I'm gonna try a simple performance test with TPL and classic code. So i'm writing a modulus class which calculates modulus with decrement operation. My function is like</p>
  
  <pre><code>long FindModulus(long n, int i)
  {
      while ( n &gt;= i )
         n -= i;
      return  n;
  }
  </code></pre>
  
  <p>My goal is replacing this loop with a Parallel For loop</p>
  
  <p>and i also want to learn can i use Parallel For with an if and break statement.</p>
  
  <p>I think i will need a lock because value of n will be changed in all threads, any code sample would be appreciated</p>
  
  <p>Thanks in advance</p>