Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID:                 26411
 Comment by:         ma-martin at hotmail dot de
 Reported by:        php at bellytime dot com
 Summary:            while {} else {}
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        *
 Block user comment: N
 Private report:     N

 New Comment:

Hey, i was also looking for some while {} else {} feature...
but i think it could be difficult to implement such a function in php.
Because the else{} event would start after the while{}-loop ends -> everytime 
after the last result!
think about it!


Previous Comments:
------------------------------------------------------------------------
[2012-01-25 12:16:57] hawkyhawk14 at gmail dot com

This is a great idea. I am currently needing something like this, but however 
got 
around it using flags and making the flag true in the while. It would be alot 
more 
convenient if there was an else!

Please add this feature!!!

------------------------------------------------------------------------
[2011-12-06 16:31:22] absimu at hotmail dot com

I agree. I think a while () else () will make things easier. I was researching 
and 
found out that it doesnt exist yet. 


while($row = mysqli_fetch_assoc($result)) { }

with al else I would fix it.. I am new in PHP,. I will try to find something to 
fix it. but if the while else is release in a new version that would be nice.

------------------------------------------------------------------------
[2011-02-18 01:14:34] ijrbiz at gmail dot com

Highly agreed, this request would be very practical for improved coding 
structure and 
follows logical language syntax nicely.

function remove_items (&$arr, $needle) {
        while ($key = array_search($needle, $arr)) {
                unset( $arr[$key] );
        } else return false; // No items present
        return true; // Item(s) removed
}

------------------------------------------------------------------------
[2010-12-19 13:08:30] trefighter2334 at aol dot com

I'd love to see something like Python's while/else logic implemented in PHP.

This logical construct would allow developers to define blocks of code in else 
{} that'd run upon a natural exit from the while(){} loop caused by said loop's 
condition becoming FALSE; however, the else {} would be skipped over if the 
loop 
exits unnaturally -- a la through a break statement or because of an exception.

It is to die for on a semi-daily basis for me (in python)... but I'm not sure 
this is what the developers above (and their examples) have in mind or not.

Either implementation would prove useful to me.

------------------------------------------------------------------------
[2008-04-09 07:51:11] ois at oisnot dot com

try {
  foreach ($nullValue as $nothing) {
    echo 'valid input';
  } else {
    //suppress notice
    echo 'null value';
  }
  //or/and
} catch (ExceptionObjectNotIterator $e) {
  //object doesnt implement Iterator
  echo $e->getMessage();
}

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1

Reply via email to