Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new combination of keywords: "break and continue" inside a nested loop breaks the inner and continues in the outer #101935

Closed
ghost opened this issue Feb 15, 2023 · 9 comments
Labels
type-feature A feature request or enhancement

Comments

@ghost
Copy link

ghost commented Feb 15, 2023

Feature or enhancement

Add new combination of keywords: "break and continue" inside a nested loop breaks the inner and continues in the outer.
This could be extended to "break and break" to break inner and outer loop or even to "break and continue and continue" to break in the most inner, continue in the second most inner and continue in the outer loop"

Pitch

We often have nested loops. Sometimes I want to continue or break the outer depending of a result of a function call in the inner. What I have to do is:

for index,row in tqdm(cellmesh_dataset.iterrows()):
[...]
  for gene in list_of_genes:
      tokenized_gene = tokenizer(gene)
      match_indexes = search_list_in_list(tokenized_context, tokenized_gene)
      if match_indexes == -1:
          break
        for index in match_indexes:
            for i in range(len(tokenized_gene)):
                outputs[index+i] = 1.0
  
  if match_indexes == -1:
      continue
[...]

What I would like to do is:

for index,row in tqdm(cellmesh_dataset.iterrows()):
[...]
  for gene in list_of_genes:
      tokenized_gene = tokenizer(gene)
      match_indexes = search_list_in_list(tokenized_context, tokenized_gene)
      if match_indexes == -1:
          break and continue # <--- this line now breaks the inner loop and continues in the outer
        for index in match_indexes:
            for i in range(len(tokenized_gene)):
                outputs[index+i] = 1.0
[...]

Previous discussion

I have never heard of anyone discussing this.

@ghost ghost added the type-feature A feature request or enhancement label Feb 15, 2023
@pochmann
Copy link
Contributor

pochmann commented Feb 15, 2023

Previous discussion

I have never heard of anyone discussing this.

Hmm, then why are you here? I just tried creating a feature request, and the template contained this:

Previous discussion

New features to Python should first be discussed elsewhere before creating issues on GitHub,
for example in the "ideas" category (https://discuss.python.org/c/ideas/6) of discuss.python.org,
or the python-ideas mailing list (https://mail.python.org/mailman3/lists/python-ideas.python.org/).

If/when you do that, please fix the IndentationError, which currently makes your code invalid and unclear. And your example's continue is pointless, since you're at the end of the loop body anyway.

@stevendaprano
Copy link
Member

This proposed API is awful. What if you want to break out of six loops? break and break and break and break and break and break. I think I died a little bit inside just typing that out.

If you search for break on the Python-Ideas mailing list, and on Discuss, you will certainly find many previous discussions about this.

@stevendaprano stevendaprano closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2023
@zware
Copy link
Member

zware commented Feb 15, 2023

@pochmann, @stevendaprano, please take care of your tone. "Why are you here?" and "This proposed API is awful" are not constructive or welcoming comments.

@zware
Copy link
Member

zware commented Feb 15, 2023

@r3dapple If this idea is something you want to pursue, a post to the Ideas section of discuss.python.org is the right way to get started. Note though that there have been discussions of very similar ideas in the past that have universally been shot down; a search for "nested loops" in the Ideas section or on the python-ideas mailing list archives might be instructive.

@pochmann
Copy link
Contributor

@zware I did, and you misquoted me.

@ghost
Copy link
Author

ghost commented Feb 15, 2023

@pochmann, @stevendaprano, please take care of your tone. "Why are you here?" and "This proposed API is awful" are not constructive or welcoming comments.

I thought the same thing. Thank you.

@stevendaprano
Copy link
Member

stevendaprano commented Feb 15, 2023 via email

@pochmann
Copy link
Contributor

pochmann commented Feb 15, 2023

@zware @stevendaprano To be clear, I didn't even mean the context of me then pointing out the template text with the information of what to do, and my suggestions of how to improve their code for a better example.

What I meant is that I didn't say "Why are you here?". I said "Hmm, then why are you here?". To me, the former sounds possibly angry or even yelling. While the "Hmm" rather avoids that. You don't yell "Hmm". Instead, it's setting a calm wondering tone. Wondering whether they perhaps weren't shown that text that I then cited. Might depend on the device, who knows.

I very deliberately included that "Hmm", precisely for the tone. Then to be told "take care of your tone", with that "Hmm" being removed and the "Why" capitalized to really give the impression that the "Hmm" wasn't there... that's not ok.

@leliel12
Copy link

leliel12 commented Apr 3, 2023

if "awful" is not a constructive term, all of the "zen of python" must be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants