This nested loop works fine when reading lists:
list = [1,2,3,4,5]
num = 0
while num < 5:
for i in list:
print(i)
num += 1
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.
f = open(r'C:\Users\Me\Python\bible.txt')
num = 0
while num < 50:
for line in f:
print(line)
num += 1
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?
listtoo. Try that again with a larger list or withnum < 3and see what happens..