I have a program like this:
def read():
while True:
for line in temp1:
if event in line:
print temp1.next()
elif date in line:
print temp1.next()
elif ending in line:
print 'End of file'
break
event = '1'
date = '2'
ending = '3'
temp1 = open('test.txt')
And test.txt looks like this:
1
ABC
2
CAB
3
The program outputs this:
ABC
CAB
And then it goes into an infinite loop. Is there a way to fix this?
breakis breaking out of the for loop, not the while loop.while 1is understood,while Trueis typically better for clarity.