On Wed, Mar 2, 2022 at 2:25 AM Steven D'Aprano <steve@pearwood.info> wrote:
> I think it's really the equivalent of
>
> for x in y:
>     if not x in c:
>         break
>     do_stuff
>
> which to me give the proposed syntax a bit more relative strength.

Forgotten the difference between continue and break, have we? :-)

Wow! Now THAT was a brain fart! Untested code and all. I often tell me students I rarely write more than two lines of code without a mistake…. 

Semantically, there is no difference between

    if not condition:
        continue
    block

and

    if condition:
        block

Sure — and as you said, there are any number of other ways to accomplish this. But my point (that was likely weakened by posting completely incorrect code) was that “block” here is often a lot more than one line, in which case I, at least, would prefer to filter out the unwanted items first, and then leave the rest of the contents of the loop the same. 

If nothing else, that allows readers of the code to know that there is not an else: down there somewhere.

but as of CPython 3.10, the byte-code from the first version is slightly
longer, so I imagine (but haven't measured) it will be ever-so-slightly
less efficient. (But unlikely to be meaningfully different.)

And I certainly wouldn’t make this choice one way or another due to a micro optimization.

-CHB

--
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython