On 03.12.2020 12:06, Jonatan wrote: > Hi, sometimes I do nested loops and I want to break specific loop, > outer/inner etc. > I need to do an ugly thing with for..else and it's annoying. > > It'd be nice if we could do so: > for i in range(10) as loop_i: > for j in range(i, i + 10) as loop_j: > if i + j == 9: > break loop_i > or something like this. > Please comment what do you think about this idea.
While that's an interesting idea, you can already handle such "break" scenarios quite well using functions/methods and "return" instead: def work(): for i in range(10): for j in range(i, i + 10): # Do work if i + j == 9: return (i, j) print(work()) For added flexibility and "continue" scenarios you can use generators. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Dec 03 2020) >>> Python Projects, Coaching and Support ... https://www.egenix.com/ >>> Python Product Development ... https://consulting.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ _______________________________________________ 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/OCDPZTFV7KFGLD2S7H3NU2HJZZJHVBSY/ Code of Conduct: http://python.org/psf/codeofconduct/