title: Nested WHILE loops in Python
body: <p>I am a beginner with Python and trying few programs. I have something like the following WHILE loop construct in Python (not exact).</p>
  <pre><code>IDLE 2.6.4      
  &gt;&gt;&gt; a=0
  &gt;&gt;&gt; b=0
  &gt;&gt;&gt; while a &lt; 4:
        a=a+1
        while b &lt; 4:
           b=b+1
           print a, b
  
    
  1 1
  1 2
  1 3
  1 4
  </code></pre>
  <p>I am expecting the outer loop to loop through 1,2,3 and 4. And I know I can do this with FOR loop like this</p>
  <pre><code>&gt;&gt;&gt; for a in range(1,5):
         for b in range(1,5):
             print a,b
  
    
  1 1
  1 2
  .. ..
  .. .. // Other lines omitted for brevity
  4 4
  </code></pre>
  <p>But, what is wrong with WHILE loop? I guess I am missing some thing obvious, but could not make out.</p>
  <p><strong>Answer:</strong>
  The corrected WHILE loop..</p>
  <pre><code>&gt;&gt;&gt; a=0
  &gt;&gt;&gt; while a &lt; 4:
      a=a+1
      b=0
      while b&lt;4:
          b=b+1
          print a,b
  
          
  1 1
  .. ..
  .. .. // Other lines omitted for brevity
  4 4
  </code></pre>
  <p><strong>P.S</strong>: Searched out SO, found <a href="https://stackoverflow.com/questions/1421323/nested-while-loop-in-python">few questions</a> but none as close to this. Don't know whether this could classified as homework, the actual program was different, the problem is what puzzles me.</p>