This change does not carry changes in the logic, only syntactic optimization.
Actually how it should work Now the logic is written like this: (Code 1) for i in range (j): ... else: if i> 5: ... The idea is to shorten it to a record like this: (Code 2) for i in range (j): ... elif i> 5: ... In fact, AST will remain unchanged. Now AST for code 1 looks like this: For ( ..., orelse = [ If (...) ] ) It will look similar for code 2 Similar for the while loop: Now the code looks like this: while x: ... else: if y: ... And it will be like this: while x: ... elif y: ... As for the real cases where it will be applicable, I have already found several in our project For example, here in Tools/importbench/importbench.py while total_time <seconds: try: total_time + = timer.timeit (1) finally: cleanup () count + = 1 else: if total_time> seconds: count - = 1 Or lib/idlelib/pyparse.py while i <n: ch = code [i] i = i + 1 ... # some other huge calculations ... else: # didn't break out of the loop, so we're still # inside a string if (lno - 1) == firstlno: # before the previous \ n in code, we were in the first # line of the string continuation = C_STRING_FIRST_LINE else: continuation = C_STRING_NEXT_LINES вс, 15 дек. 2019 г. в 02:52, Ned Batchelder <n...@nedbatchelder.com>: > On 12/14/19 4:37 PM, komissar.off.and...@gmail.com wrote: > > Hello! > > I think it will be useful in Python syntax if we can use "elif" in "for" > and "while" statements besides "else" > > > > Example > > for i in range(j): > > ... > > elif i > 5: > > ... > > else: > > ... > > > > What you think about this change? > > Can you say what you want it to *mean*? What does it do? > > --Ned. > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/ATLUW77NCYIUH6QGY7B2DCRA6VV2IWNA/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CJ7WF7EJQTIVA6HSFER76IU5GNLQPFAD/ Code of Conduct: http://python.org/psf/codeofconduct/