label_a:
   $i=0;
 label_b:
   $i++;
   while($i<10) {
     if(foo()) continue label_b;
     else {
       if(bar($i++)) goto label_a;
     }
   }

And that would be a parse error.

break/continue label only works when the label IMMEDIATELY preceeds the loop construct thus saying "I identify this loop at `label_foo`".

Here's another reason for break being distinct from goto:

foo:
foreach($arr as $val) {
 if (cond1) break foo; /* Leave the loop entirely */
 if (cond2) continue foo; /* Jump to next itteration in loop */
 if (cond3) goto foo; /* Restart the loop from the beginning */
}

Each type of label-targeted statement does a different thing. But if that is ((really)) is confusing then you're right, it's not a good thing. break 1;/continue 1; would cover the first two conditions in that example just fine. To me, I see more consistency in working on the foo loop with foo on all statements.

-Sara

Still +1 goto, +0 goto with labeled breaks.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to