Req #51743 [Bgs]: An improvement to control blocks, `else` on loop
| From: | petepostma at gmail dot com | Date: | Wed, 01 Dec 2010 19:35:48 +0000 |
| Subject: | Req #51743 [Bgs]: An improvement to control blocks, `else` on loop | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-156661@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51743&edit=1
ID: 51743
User updated by: petepostma at gmail dot com
Reported by: petepostma at gmail dot com
Summary: An improvement to control blocks,
else on loop
Status: Bogus
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: ALL
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Sorry, I did not search on foreach loops when I posted. I was
specifically looking for while, for, and do.
Can I at least get a duplicate? After spending the last 9 years using,
testing and proofing PHP "Bogus" and "Spam" feels insulting.
Previous Comments:
------------------------------------------------------------------------
[2010-12-01 15:37:56] jani@php.net
Already requested in bug #46240, please search before spamming the bug
database!
------------------------------------------------------------------------
[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