title: Functional programming — for and while loops
body: <p>I'm trying to write <code>for</code> and <code>while</code> loops in Python — functional programming style. </p>
  
  <p>I think <code>for</code> construct is fine, but <code>while</code> doesn't work, it runs infinitely. </p>
  
  <pre><code># for loop
  lst = [1, 2, 3]
  def fun(e):
     return e
  print map(fun, lst)
  
  
  # while loop
  i = 1
  def whileloop():
      global i
      print i
      i = i+1
  while_FP = lambda: ((i &lt; 5) and whileloop()) or while_FP()
  while_FP()
  </code></pre>