Why not start at break 0 not break 1, similar to sequences starting at index 0?

Maybe if break alone without integer, it breaks from the loop it is at similar to the behavior we have right now in Python.

E.g.,

for matrix in matrix_array : # Index 0

for x in range(0,10) : # Index 1

for y in range(0,10) : # Index 2

for z in range(0,10) : # Index 3

if matrix[x][y][z] == 0 :

print("Found !")

continue 3 # which is equivalent to continue/break alone

Ok, so, that's yet another proposition; what I meant by "the number of loops to break" was not to number the loops in a constant way, but rather to specify the number of loop-blocks whose flow to break. In other words, my version's behavior depends on the "callsite" if you want to target a specific line of code.

To me, to "manually" do "break n", you could read the script upwards starting at the break's line, and count the number of for/while loops you encounter; when your count matches break's parameter, switch back to the standard code flow. Your proposal, on the other hand, requires getting back to the start of the script and counting loops downwards. That's not how I understand the standard break/continue's behavior, tell me if I'm mistaken :-[

I meant to start numbering at 1, not at 0, also because of the semantics of the statement : "break n" would mean "break from n loops", not "break up to the n-th nested loop". Therefore, the parameter-less version, "break;", witch I always read as "break out of the (innermost) loop" would read "break 1". For me, that's not an index after "break", it's a cardinal: we don't break "the loop 0", we break "the first loop".

An added benefit from numbering from one would be to allow a "break 0" statement with no effect, e.g. for debugging purposes. (I can see other, more esoteric uses, too, if arbitrary expressions were allowed, but, hey, consenting adults here.)

I have tried to search for examples of numbering from 1 in Python, I'm sure there are some, but I can't recall any just now ;-). Anyway, that's not the core point of the proposal; I can concede that one.

One final point : with my way of numbering, the default parameter would always be 1 (or 0, whatever), as opposed to your suggestion where you number the loops from outermost to innermost. In our example, if I added / removed a loop in the block, a bare "continue;" would have its default parameter vary implicitly. Therefore, "continue 3", as you put it, would not be equivalent to "continue" alone. I don't like that way of doing it : a default parameter has always been a known, constant value ! Of course, you could always differentiate between "continue" and "continue <n>", saying they are two different statements that behave differently, but then I'd rather have them named differently…

Regards,

Alexis