One of the problems of the suggested syntax is that the use of an if clause can, at first glance, create an ambiguity: is it a stand-alone if clause or part of a loop. Something that could help reduce the ambiguity would be using elif.
Thus, using only existing keywords, it might be interesting to implement something like:
for item in iterable:
# code block 1
elif pass:
# code block 2
elif not break:
# code block 3
which would be translated, using the current syntax, as
looped = False
for item in iterable:
looped = True
# code block 1
else:
if not looped:
# code block 2
else:
# code block 3
The simpler case, corresponding to the existing else clause would be written as
for item in iterable:
# code block 1
elif not break:
# code block 2
https://mail.python.org/archives/list/python-ideas@python.org/thread/WNKNETPRGQ3MPQOVG4KG2QV6L7KAPNWM/#N65ZZJPLN6LBPQOURDKJNXWGT64T3ZZK is a discussion on various additions to the
else
clause infor
andwhile
loops.One of the problems of the suggested syntax is that the use of an
if
clause can, at first glance, create an ambiguity: is it a stand-alone if clause or part of a loop. Something that could help reduce the ambiguity would be usingelif
.Thus, using only existing keywords, it might be interesting to implement something like:
which would be translated, using the current syntax, as
The simpler case, corresponding to the existing
else
clause would be written as