ID: 44369
Updated by: [EMAIL PROTECTED]
Reported By: php at xyzzy dot cjb dot net
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: Mac OS X 10.5.2
PHP Version: 5.2.5
New Comment:
PHP 6 has goto which can be used for that.
Previous Comments:
------------------------------------------------------------------------
[2008-03-08 06:56:00] php at xyzzy dot cjb dot net
Description:
------------
This is an enhancement request to add loop labels to PHP. Currently, to
break out of nested loops, PHP allows you to specify a number to a
break
or continue statement. It would increase code clarity and
maintainability to be able to specify a textual label of the loop to
continue or break out of.
This is similar to Bug #29287 "Request: Line labels and goto" except
that I'm not requesting goto, which is what that bug was mostly used to
discuss before being closed. This ticket is specifically for the
feature
of adding loop labels, which was not adequately discussed in #29287.
Reproduce code:
---------------
An example of a nested loop (admittedly not a very useful example), how
PHP currently allows you to write it:
for ($i = 0; $i < 5; ++$i)
{
print "$i: ";
for ($j = 0; $j < 5; ++$j)
{
print "$j ";
if ($j == 2 && $i == 4)
continue 2;
}
print "\n";
}
How I would like to be able to write it:
ROW: for ($i = 0; $i < 5; ++$i)
{
print "$i: ";
COLUMN: for ($j = 0; $j < 5; ++$j)
{
print "$j ";
if ($j == 2 && $i == 4)
continue ROW;
}
print "\n";
}
Expected result:
----------------
Both examples should behave the same, if this feature is implemented.
Actual result:
--------------
Parse error: syntax error, unexpected ':' in /private/tmp/a.php on line
2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44369&edit=1