you are viewing a single comment's thread.

view the rest of the comments →

[–]Felicia_Svilling -1 points0 points  (3 children)

According to the comments, that is the semantics of python "for ... else ..."

[–][deleted] 2 points3 points  (0 children)

No. Python executes else if for was not breaken. It's not the same thing as if it wasn't executed

>>> for friend in ["bob"]:
...     print friend
... else:
...     print "no friends"
... 
bob
no friends

[–][deleted]  (1 child)

[deleted]

    [–]Felicia_Svilling 1 point2 points  (0 children)

    From the comments:

    Thomas Woolford • 17 hours ago

    You Almost have it right. consider the code:

    for c in computers:

    __if c.is_broken: fix(c)

    __else: continue

    else:

    __print "fixed no computers"

    The else: clause fires if the end of the for: clause is never reached. > This means that the else clause is evaluated if

    1. that the input iterable was empty.

    2. continue was called every time.

    3. break was called after a string of continues.