[Tutor] break and exit

James Rieve jrieve at gmail.com
Fri Nov 21 05:10:13 CET 2014


I accidently used 'exit' in a loop where I meant to use 'break' and, in that
case, the program seemed to work as expected but in some cases 'exit' seems
to behave differently from 'break'. For example, in this code snippet using
'exit' or 'break' produces the same result:

for i in range(10):
    if i > 3:
        exit
    else:
        print(i)
print('out of loop')

But in this case they behave differently:

for i in range(10):
    if i > 3:
        break   # try using exit here.
    else:
        print(i)
else:
    print('for loop else statement')

print('out of loop')

Does anyone have any pointers to descriptions of 'exit', what it is, what it
means, how It's used, etc.?




More information about the Tutor mailing list