News for hackers. Stuff that matters.
Re:The optional “else” in Python loops by maxerickson on Thursday July 17, 2014 @08:45PM (#8051113)
Just to illustrate:

    >>> for item in (1,2):
    	print(item)
    else:
    	print('Done!')

    1
    2
    Done!
    >>> for item in (1,2):
    	print(item)
    	break
    else:
    	print('Done!')
    
    1
    >>>
edit: also:

    >>> for item in ():
    	print(item)
    else:
    	print('Done')
    
    Done

There are no comments on this comment yet.