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

 ID:                 51743
 Updated by:         j...@php.net
 Reported by:        petepostma at gmail dot com
 Summary:            An improvement to control blocks, `else` on loop
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
-Package:            Unknown/Other Function
+Package:            Scripting Engine problem
 Operating System:   ALL
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Already requested in bug #46240, please search before spamming the bug
database!


Previous Comments:
------------------------------------------------------------------------
[2010-05-05 00:09:04] petepostma at gmail dot com

Description:
------------
It would be totally kickin' if we could have 'ELSE' on a loop control.

for example, my current code:

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

$results = mysql_query($sql);

if(!$results || mysql_errno())

  die("gaaah!");



if(mysql_num_rows()<1)

  echo "<tr><td>No results found</td></tr>";

else {

  while($row = mysql_fetch_assoc($result)) {

    //echo rows of a table or something...

  }

}

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

could be:

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

$results = mysql_query($sql);

if(!$results || mysql_errno())

  die("gaaah!");



while($row = mysql_fetch_assoc($result)) {

  //echo rows of a table or something...

} ELSE {

  echo "<tr><td>No results found</td></tr>";

}

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



The definition of an else on a loop would be "If the initial loop
condition fails in such a way that the loop never iterates (once or
more), then the ELSE block will be executed instead. Loops supported
would be while, for, and foreach



This would be great for debugging as well, when you're trying to figure
out why things never executed, if there was an 'ELSE { echo " -DEGUB:
never entered lool"; } on loops that must be entered it would tip
programmer's off right away.



just think about it:

foreach($items as $item) {

   echo "Item: $item\r\n";

} else {

   echo "No items found.\r\n";

}



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



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

Reply via email to