How about reserving unicode numeric superscript characters 0..9 as label identifiers only to be used for loop & break, etc. Then the example below would become:
while¹ not processed():
for x in the_stuff as 37:
break¹
if all_done(x):
I don't really care how the labels are spelled, just that they are spelled on the line that defines the loop. For example:
while not processed() as 1:
for x in the_stuff as 37:
if all_done(x):
break 1
I don't think this feels Pythonic, but if the labels were exclusively one-digit positive integers, that would limit named loop depth to 9. That is a good thing. Anything over 4 levels is questionable, anything over 6 is monstrous. So that's extra leeway for anything that is actually a good idea. But I think "use a natural number" and rely on "we're all adults here" is more likely to fit in Python.Numbers like 1 and 37 are pretty clearly not binding targets. By convention, using numbers 1, 2, 3, 4 for successive levels might be good. But it wouldn't break directly if you added or removed a nested loop as long as you kept its number. That said, allowing slightly more descriptive names than "2" seems sorta nice. Using sigils to make it "obviously not a binding target" is way too much ugly for the limited need.
I agree with you that the point of `break x` — labeled or numbered — is to target a specific loop to "jump" to, but I'm not comfortable with introducing labels to Python. The reason for this is that they look too much like identifiers, and should, therefore, be bound to something, following Python's motto of "everything is an object". I don't see what kind of an object could be bound to that, what kind of API it would expose, how it could be manipulated/re-affected, it behavior out of the loop…
I like how you two mixed "numbered loops" and "labeled loops" into "numbers as labels" 😂
Yeah, I could go with that: either free naming and a convention to use digits, or restricting the charset somewhat. I wouldn't go with "unicode numeric superscript characters 0..9", though, for the simple reason that I can't type them easily, with the exception of "²" (on an AZERTY keyboard).
And now I have a syntactic remark: by reading your example code, I just realized I don't like the `as` keyword there, because `as` usually binds a value to a variable (`with ... as ...`, `import ... as ...`, `except ... as ...`). I don't have any better idea right now, though, but I'll let you know if I find anything better 😉
Cheers,
Alexis