Re: Feature Suggestion: "repeat" statement in loops
Jen Kris via Python-Dev <[email protected]> Fri, 27 Jan 2023 19:39:06 +0100 (CET)
| Newsgroups | gmane.comp.python.devel |
|---|---|
| Message-ID | <[email protected]> |
--===============7251947428672764781== Content-Type: multipart/alternative; boundary="----=_Part_111863_1853217602.1674844746266" ------=_Part_111863_1853217602.1674844746266 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Why would "if not A" also be true when you repeat the current iteration?=C2= =A0 What keeps this from becoming an endless loop? Jan 26, 2023, 11:45 by [email protected]: > Hi all, > > i would like to suggest the following Python feature. It naturally happen= s that one want's to repeat the current iteration of a for loop for example= after an error happened. For this purpose, I usually set a flag and put a = while loop inside my for loop. A simple "repeat" statement just like "conti= nue" or "break" would make the code much more readable. > > > This is my solution at the moment with A being checked: > > for _ in range(n): > =C2=A0=C2=A0=C2=A0 flag =3D True > =C2=A0=C2=A0=C2=A0 while flag: > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 ... > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if A: > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 flag =3D False #= go to next iteration > > > I would suggest the repeat statement in the following sense > > for _ in range(n): > =C2=A0=C2=A0=C2=A0 ... > =C2=A0=C2=A0=C2=A0 if not A: > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 repeat # repeat current iteration > > Notice the "not" in the if clause. I am really looking forwars to hear yo= ur opinions. > > Best regards > Thomas > > _______________________________________________ > Python-Dev mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at https://mail.python.org/archives/list/python-dev@pyth= on.org/message/LNER4MH6IT6HBFKFVTUOJ225PTCZSRRC/ > Code of Conduct: http://python.org/psf/codeofconduct/ > ------=_Part_111863_1853217602.1674844746266 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <html> <head> <meta http-equiv=3D"content-type" content=3D"text/html; charset=3DUTF-8= "> </head> <body> <div>Why would "if not A" also be true when you repeat the current iteratio= n? What keeps this from becoming an endless loop?<br></div><div><br><= /div><div><br></div><div>Jan 26, 2023, 11:45 by [email protected]:<= br></div><blockquote class=3D"tutanota_quote" style=3D"border-left: 1px sol= id #93A3B8; padding-left: 10px; margin-left: 5px;"><div>Hi all,<br></div><d= iv><br></div><div>i would like to suggest the following Python feature. It = naturally happens that one want's to repeat the current iteration of a for = loop for example after an error happened. For this purpose, I usually set a= flag and put a while loop inside my for loop. A simple "repeat" statement = just like "continue" or "break" would make the code much more readable.<br>= </div><div><br></div><div><br></div><div>This is my solution at the moment = with A being checked:<br></div><div><br></div><div>for _ in range(n):<br></= div><div> flag =3D True<br></div><div> = while flag:<br></div><div> ...<br></di= v><div> if A:<br></div><div> &nbs= p; flag =3D False # go to next = iteration<br></div><div><br></div><div><br></div><div>I would suggest the r= epeat statement in the following sense<br></div><div><br></div><div>for _ i= n range(n):<br></div><div> ...<br></div><div> = if not A:<br></div><div> repeat= # repeat current iteration<br></div><div><br></div><div>Notice the "not" i= n the if clause. I am really looking forwars to hear your opinions.<br></di= v><div><br></div><div>Best regards<br></div><div>Thomas<br></div><div><br><= /div><div>_______________________________________________<br></div><div>Pyt= hon-Dev mailing list -- [email protected]<br></div><div>To unsubscribe = send an email to [email protected]<br></div><div>https://mail.pyt= hon.org/mailman3/lists/python-dev.python.org/<br></div><div>Message archive= d at https://mail.python.org/archives/list/[email protected]/message/LN= ER4MH6IT6HBFKFVTUOJ225PTCZSRRC/<br></div><div>Code of Conduct: http://pytho= n.org/psf/codeofconduct/<br></div></blockquote><div dir=3D"auto"><br></div>= </body> </html> ------=_Part_111863_1853217602.1674844746266-- --===============7251947428672764781== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline