Hi everyone,

I'm not in favor of naming loops, as this looks too much like variable. (What happens when variable names and loop names names collide ? Does the loop identifier bind to anything ?)

On the other hand, I like the feature very much, and I have thought about it in the past. My take on this matter was to allow `break` and `continue` to take an optional integer parameter (default 1) for the number of loops to break.

For example, for searching a value in matrixes :

```py

for matrix in matrix_array :

    for x in range(0,10) :

        for y in range(0,10) :

            for z in range(0,10) :

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

                    print("Found !")

                    continue 4

    print("This matrix has no zero in it…")

```

Here, the `continue 4` would make the program flow jump to the next iteration in the outermost loop.

This seems much cleaner to me than a flag to check against at the beginning of each loop, and is certainly much more acceptable than bringing back the /evil/ `goto`.

Not involving any identifier looks like a plus to me, as it would not require changes in the loop semantics, only an optional parameter in `break` and `continue`.


Now the questions I haven't yet found answers about are :

 * Is `break 0` allowed ?
 * Is `x = 3; break x` allowed ?
 * What does happen with `break "not an integer"` ? (an Exception gets
   raised, I guess, but…)


What do you think about this fork of the proposal ?


Regards,

Alexis Masson

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/RGY6MNTYEJ252XQQDGIKKBLQP3ZIUY4W/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to