|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-12-01 15:37 UTC] jani@php.net
-Status: Open
+Status: Bogus
-Package: Unknown/Other Function
+Package: Scripting Engine problem
[2010-12-01 15:37 UTC] jani@php.net
[2010-12-01 20:35 UTC] petepostma at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 09:00:02 2025 UTC |
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"; }