title: Python: Using a generator inside a while loop
body: <p>Here's my code so far:</p>
  
  <pre><code>def down_data(h):
      t = 0
      while h &gt; 0:
          t += .0001
          h = -4.9*t**2 + 1
          v = g*t
          yield h, v
      return False
  
  def up_data(v):
      t = 0
      h = 0
      vel = v
      while h &lt; 1:
          t += .0001
          h = -4.9*t**2 - v*t
          vel = -9.8*t - v
          yield h, vel, t
  </code></pre>
  
  <p>What I'm trying to do is get my <code>main()</code> function to output the values of <code>down_data(1)</code> for as long as that function remains valid. Running this incomplete code just sets up an infinite loop and I'm not sure why.</p>
  
  <p>I'm trying to combine these two functions to simulate a bouncing ball, but stitching them together has proven difficult because of the yield function. I've tried creating a <code>main()</code> and running <code>while</code> loop over one of the functions, but this creates an infinite loop. Here's the <code>main()</code> I've tried:</p>
  
  <pre><code>def main():
      data = [] 
      while down_data(1):
          data.append(down_data(1))
      print(data)
  </code></pre>
  
  <p>Is there maybe an easier way to do this? The <code>main()</code> function I'm after would be something like this: </p>
  
  <p>Edit: I've also tried out this, but the same problem happens; the while loop doesn't close out to move to the next <code>i</code>: </p>
  
  <pre><code>def main():
      data = []
      for i in down_data(1):
          while i[0] &gt; 0:
              data.append(i[0])
              continue
      print(data)
  </code></pre>