title: Breaking a loop using TakeWhile when a count or length condition is meet
body: <p>I'm  trying to figure out a way to use TakeWhile to break a loop when some conditions are meet.</p>
  
  <p>i.e.</p>
  
  <pre><code>var i = 0;
  List&lt;IContent&gt; t = new List&lt;IContent&gt;();
  
  // children is a List&lt;&gt; with lots of items
  foreach (var x in children)
  {
      if (i &gt;= 10)
      {
          break;
      }
  
      if (x.ContentTypeID == 123)
      {
          i++;
          t.Add(x);
      }    
  }
  </code></pre>
  
  <p>What I'd like to do is to write that using Linq instead</p>
  
  <pre><code>var i = 0;
  var a = children.TakeWhile(
      x =&gt;
      {
          if (i &gt;= 10)
          {
              break; // wont work
          }
  
          if (x.ContentTypeID == 123)
          {
              i++;
              return true;
          }
  
          return false;
      });
  </code></pre>
  
  <p>Any ideas? Thanks</p>