Pythonic enumeration of while loop
Question: Python has an elegant way of automatically generating a counter variable in
`for` loops: the `enumerate` function. This saves the need of initializing and
incrementing a counter variable. Counter variables are also ugly because they
are often useless once the loop is finished, yet their scope is not the scope
of the loop, so they occupy the namespace without need (although I am not sure
whether `enumerate` actually solves this).

My question is, whether there is a similar pythonic solution for `while`
loops. `enumerate` won't work for `while` loops since `enumerate` returns an
iterator. Ideally, the solution should be "pythonic" and not require function
definitions.

For example:

    
    
    x=0
    c=0
    while x<10:
      x=int(raw_input())
      print x,c
      c+=1
    

In this case we would want to avoid initializing and incrementing `c`.

**Clarification:**

This can be done with an endless `for` loop with manual termination as some
have suggested, but I am looking for a solution that makes the code clearer,
and I don't think that solution makes the code clearer in this case.


Answer: Again with the
[`itertools`](http://docs.python.org/2/library/itertools.html)...

    
    
    import itertools
    
    for c, x in enumerate(
        itertools.takewhile(lambda v: v < 10,
          (int(raw_input()) for z in itertools.count())
        )
      ):
      print c, x
    

