for / while else doesn't make sense
Lawrence D’Oliveiro
lawrencedo99 at gmail.com
Wed Jun 1 19:39:27 EDT 2016
On Friday, May 20, 2016 at 4:43:56 AM UTC+12, Herkermer Sherwood wrote:
> Most keywords in Python make linguistic sense, but using "else" in for and
> while structures is kludgy and misleading.
My objection is not to the choice of keyword, it’s to the whole design of the loop construct.
It turns out C-style for-loops “for (init; test; incr) ...” are very versatile. If my loop has more than one exit, I use the endless form “for (;;)” and do an explicit “break” for every exit condition.
Also, they let me declare a variable that is scoped to the loop, that is initialized just once before the loop starts, e.g.
for (int loopvar = initial_value;;)
{
if (loopvar == limit)
break;
... processing ...
if (found_what_im_looking_for)
break;
++loopvar;
} /*for*/
I wish I could do this in Python...
More information about the Python-list
mailing list