Re: Feature Suggestion: "repeat" statement in loops

Chris Angelico <[email protected]> Fri, 27 Jan 2023 09:04:44 +1100
Newsgroups gmane.comp.python.devel
Message-ID <CAPTjJmo75Sv5gjxabdD7V99e08-u41rbYeUVmkwRnBh++51kng@mail.gmail.com>
On Fri, 27 Jan 2023 at 06:42, Thomas Ratzke <[email protected]> wrote:
>
> Hi all,
>
> 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.
>
>
> This is my solution at the moment with A being checked:
>
> for _ in range(n):
>      flag = True
>      while flag:
>          ...
>          if A:
>              flag = False # go to next iteration
>

Why not use break?

ChrisA