From:             php at xyzzy dot cjb dot net
Operating system: Mac OS X 10.5.2
PHP version:      5.2.5
PHP Bug Type:     Feature/Change Request
Bug description:  PHP Loop Labels

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 bug report at http://bugs.php.net/?id=44369&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44369&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44369&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44369&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44369&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44369&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44369&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44369&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44369&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44369&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44369&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44369&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44369&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44369&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44369&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44369&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44369&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44369&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44369&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44369&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44369&r=mysqlcfg

Reply via email to