Hello, I was thinking about giving loops names. And It would be interesting if through this name in a continue or break statement could be called. A little example what I mean: loop "outloop" while True: actmonth = datetime.datetime.now().month loop "innerloop" for i in range(0, int(input())): if datetime.datetime.now().month != actmonth: break "outloop" else: print("Waiting for a new Month...") # Do some stuff if loop ended before new Month Without giving names it's always needed to define a new variable and a if statement outside of the innerloop, like this: while True: actmonth = datetime.datetime.now().month shouldend = False for i in range(0, int(input())): if datetime.datetime.now().month != actmonth: shouldend = True break else: print("Waiting for a new Month...") if shouldend: break # Do some stuff if loop ended before new Month It's possible without it, but it is more readable. Maybe another option is, but that's too deep, to make loops to objects. Best Regards, Oskar Promeuschel
A very similar proposal was rejected: https://www.python.org/dev/peps/pep-3136/. Also, see the discussion in https://mail.python.org/archives/list/python-ideas@python.org/thread/26PAGUT... . If you'd still like to propose this, you'll have to present an argument against the reasons why the other proposals were rejected. On Mon, Dec 30, 2019 at 10:19 AM Oskar Promeuschel < Promeuschel_Oskar@lsh-marquartstein.de> wrote:
Hello,
I was thinking about giving loops names. And It would be interesting if through this name in a continue or break statement could be called.
A little example what I mean:
loop *"outloop" **while True*: actmonth = datetime.datetime.now().month loop *"innerloop" **for *i *in *range(0, int(input())): *if *datetime.datetime.now().month != actmonth: *break * *"outloop" **else*: print(*"Waiting for a new Month..."*)
*# Do some stuff if loop ended before new Month*
Without giving names it’s always needed to define a new variable and a if statement outside of the innerloop, like this:
*while True*: actmonth = datetime.datetime.now().month shouldend = *False for *i *in *range(0, int(input())): *if *datetime.datetime.now().month != actmonth: shouldend =
*True break else*: print(*"Waiting for a new Month..."*)
*if *shouldend:
*break **# Do some stuff if loop ended before new Month*
It’s possible without it, but it is more readable.
Maybe another option is, but that’s too deep, to make loops to objects.
Best Regards,
Oskar Promeuschel _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/MWOQ67... Code of Conduct: http://python.org/psf/codeofconduct/
participants (2)
-
Kyle Stanley
-
Oskar Promeuschel