On Sat, Oct 8, 2022 at 5:35 PM rbowman <bow...@montana.com> wrote: > On 10/7/22 21:32, Axy wrote: > > So, seriously, why they needed else if the following pieces produce same > > result? Does anyone know or remember their motivation? > > In real scenarios there would be more logic in the for block that would > meet a condition and break out of the loop. If the condition is never > met, the else block runs. To steal from w3schools: > > > fruits = ["apple", "peach", "cherry"] > for x in fruits: > print(x) > if x == "banana": > break > else: > print("Yes we got no bananas") >
I wonder if for/else could have been less confusing if it was referred to as for-break-else and if the else clause was only valid syntax if the for loop actually contained a break statement in the first place. -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER calvin.speal...@redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] <https://red.ht/sig> TRIED. TESTED. TRUSTED. <https://redhat.com/trusted> -- https://mail.python.org/mailman/listinfo/python-list