On Fri, May 11, 2012 at 2:33 AM, Alexander Moskaliov <ir...@irker.net> wrote: > > I think the main idea of this RFC: Run the code, if we had never entered > in loop. > In this case more sence to change "for .. else" condition to this: > If second expression is equal FALSE before looping(but after run first > expression of course), we run "else" code. > > By example: > for (exp1;exp2;exp3) { > exp4; > } else { > exp5; > } > > must be equal > $notLooping = true; > for (exp1;exp2;exp3) { > exp4; > $notLooping = false; > } > if ($notLooping) { > exp5; > } >
Yes... That's just what I had in the RFC. Except I used the name $loop_entered, and then checked for it being false, and you used variable $notLooping, and checked for it being true. That is the same thing. Hey, I noticed you CC'ed internals, does that mean everyone on the list is getting this? Sorry, not entirely familiar with how these mailing lists work. On Fri, May 11, 2012 at 6:21 AM, Nikita Popov <nikita....@googlemail.com> wrote: > Python already uses the for .. else syntax, but with different > semantics: In Python the else clause is only executed, if the loop > isn't left using break. See this article for more info: > http://psung.blogspot.de/2007/12/for-else-in-python.html > > Thus I'm not sure that it really makes sense for us to introduce this > syntax with a completely different meaning. > > Nikita Python isn't always right in how it does things. I find python for...else logic to have fewer real-life use-cases than what is being proposed here. I'm speaking from my experience, of course, and not saying it's true for every project out there... But if the comments to those bugs are any indication, it is true for most people. You will notice that all 3 proposals (spanning almost 10 years) advocate the non-python logic. And even if you look at the example from your article, it does *not* demonstrate usefulness of for...else in python. I can write the same code without for...else and without any flag variables by just returning from the function, instead of breaking: def contains_even_number(l): "Prints whether or not the list l contains an even number." for elt in l: if elt % 2 == 0: print "list contains an even number" return print "list does not contain an even number" -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php