title: Using while in list comprehension or generator expressions
body: <p>I can use <code>if</code> and <code>for</code> in list comprehensions/generator expressions as</p>
  
  <pre><code>list(i for i in range(100) if i*i &lt; 30)
  </code></pre>
  
  <p>I know this is not the most efficient but bear with me as the condition could be much more complicated and this is just an example. However, this still goes through hundred iterations and only yields a value in the first 6. Is there a way to tell the generator expression where to stop with something like this:</p>
  
  <pre><code>list(i for i in range(100) while i*i &lt; 30)
  </code></pre>
  
  <p>However, <code>while</code> is not understood in generator expressions. So, my question is, how do I write a generator expression with a stopping condition so it does not continue computation, even if it doesn't yield new values.</p>