"for/while ... break(by any means) ... else" make sense?

jfong at ms4.hinet.net jfong at ms4.hinet.net
Tue Jun 28 21:41:21 EDT 2016


Anyone who wrote the code below must be insane:-)

    for x in range(3):
        print(x)
    else:
        print('I am done')

But here it seems perfectly OK:

    for x in range(3):
        print(x)
        if x == 1:  break
    else:
        print('I am done')

To me, the "else" was bonded with "break" (or return, or raise, or...),
not "for". It make sense:-)

--Jach




More information about the Python-list mailing list