title: Python - Nested loop that doesn't work when reading a file
body: <p>This nested loop works fine when reading lists:</p>
  
  <pre><code>list = [1,2,3,4,5]
  num = 0
  while num &lt; 5:
    for i in list:
       print(i)
       num += 1
  </code></pre>
  
  <p>This loop will print all elements in the list. The problem is that it doesn't work at all when reading textfiles. Instead of printing the first 5 lines of text it will read through all and print them. </p>
  
  <pre><code>f = open(r'C:\Users\Me\Python\bible.txt')
  num = 0
  while num &lt; 50:
     for line in f:
        print(line)
        num += 1
  </code></pre>
  
  <p>I can only assume that the num variable doesn't increase after each iteration, is there a reason for this, and is there a solution?</p>