# Labeled Breaks (not the G-word)

- Thread: https://externals.io/message/20807
- Original archive: https://news-web.php.net/php.internals/20807
- Started by Ford on 2005-11-29T09:39:01+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #20807 — Ford — 2005-11-29T09:39:01+00:00

URL: https://externals.io/message/20807#20807

> I feel we're comparing apples with oranges here.
> 
> Break; is for breaking out of loops. It shouldn't have anything to do
> with jumping to somewhere else. Let's say *if* PHP supported jumping
> through the code. The following should then be two different things:
> 
> while (loop) {
>     goto LABEL;
> }
> > […]
> 
> while (loop) {
>     break;
> }
> 
> I think the question here is if we want to implement jumping
> through the
> code or not. If we do jumping in the code, this should be a
> full-fledged feature. If not, there should be no jumping. And it
> should, in my opinion, certainly not change the way break; works.

I'm completely indifferent about goto (in any form), but *PLEASE* can we have labelled break/continue -- something like:

  LABEL: while (cond):
    ...
    break LABEL;
    ...
  endwhile;

or

  while LABEL (cond):
    ...
    break LABEL;
    ...
  endwhile;

or

  while (cond) LABEL:
    ...
    break LABEL;
    ...
  endwhile;

I can't tell you the number of times I've broken my own code by adding or removing an inner loop and failing to notice that a break/continue count needs incrementing/decrementing.  Labelled breaks are a relatively simple addition to the syntax that would improve the programming experience out of all proportion.  Yes it's complete syntactic sugar -- it doesn't do anything you can't currently do, just does it in a much more friendly way -- but incredibly helpful sugar ;)

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 


To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

---

## #20808 — Ron Korving — 2005-11-29T10:02:44+00:00

URL: https://externals.io/message/20807#20808 · In reply to: #20807

I agree. Like you I couldn't really care about a 'goto', I'd probably never 
use it. But labeled breaks would really add something to the language. The 
current break counters aren't very user friendly if you ask me.

I'm very much in favor of:

LABEL: while (cond)
{
  ...
  break LABEL;
  ...
}

I've seen it being mentioned that the 'LABEL' would be appended to the while 
loop, something like this:

while (cond)
{
  ...
  break LABEL;
  ...
}
LABEL:

But I think that's absolutely hideous and looks like a 'goto' (which is most 
likely why people began talking about adding 'goto' in the first place). If 
it were up to me (and it's not), 'goto' will not be implemented in any form 
and the break keyword can refer to numbers and labels and in case of the 
latter, these would be PREpended to the loop construct.

Ron



""Ford, Mike"" <M.Ford@leedsmet.ac.uk> schreef in bericht 
news:CDA511FF6152D14E922434CE338CE8BB275842@leedsmet-exch1.leedsmet.ac.uk...
I'm completely indifferent about goto (in any form), but *PLEASE* can we 
have labelled break/continue -- something like:

  LABEL: while (cond):
    ...
    break LABEL;
    ...
  endwhile;

or

  while LABEL (cond):
    ...
    break LABEL;
    ...
  endwhile;

or

  while (cond) LABEL:
    ...
    break LABEL;
    ...
  endwhile;

I can't tell you the number of times I've broken my own code by adding or 
removing an inner loop and failing to notice that a break/continue count 
needs incrementing/decrementing.  Labelled breaks are a relatively simple 
addition to the syntax that would improve the programming experience out of 
all proportion.  Yes it's complete syntactic sugar -- it doesn't do anything 
you can't currently do, just does it in a much more friendly way -- but 
incredibly helpful sugar ;)

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

---

## #20810 — Bart de Boer — 2005-11-29T10:49:27+00:00

URL: https://externals.io/message/20807#20810 · In reply to: #20808

I agree.

Although there's aanother thread running about namespaces that are about 
to do something with ':' as well. Watch out that there aren't conflicts?


Ron Korving wrote:
> I agree. Like you I couldn't really care about a 'goto', I'd probably never 
> use it. But labeled breaks would really add something to the language. The 
> current break counters aren't very user friendly if you ask me.
> 
> I'm very much in favor of:
> 
> LABEL: while (cond)
> {
>   ...
>   break LABEL;
>   ...
> }
> 
> I've seen it being mentioned that the 'LABEL' would be appended to the while 
> loop, something like this:
> 
> while (cond)
> {
>   ...
>   break LABEL;
>   ...
> }
> LABEL:
> 
> But I think that's absolutely hideous and looks like a 'goto' (which is most 
> likely why people began talking about adding 'goto' in the first place). If 
> it were up to me (and it's not), 'goto' will not be implemented in any form 
> and the break keyword can refer to numbers and labels and in case of the 
> latter, these would be PREpended to the loop construct.
> 
> Ron
> 
> 
> 
> ""Ford, Mike"" <M.Ford@leedsmet.ac.uk> schreef in bericht 
> news:CDA511FF6152D14E922434CE338CE8BB275842@leedsmet-exch1.leedsmet.ac.uk...
> I'm completely indifferent about goto (in any form), but *PLEASE* can we 
> have labelled break/continue -- something like:
> 
>   LABEL: while (cond):
>     ...
>     break LABEL;
>     ...
>   endwhile;
> 
> or
> 
>   while LABEL (cond):
>     ...
>     break LABEL;
>     ...
>   endwhile;
> 
> or
> 
>   while (cond) LABEL:
>     ...
>     break LABEL;
>     ...
>   endwhile;
> 
> I can't tell you the number of times I've broken my own code by adding or 
> removing an inner loop and failing to notice that a break/continue count 
> needs incrementing/decrementing.  Labelled breaks are a relatively simple 
> addition to the syntax that would improve the programming experience out of 
> all proportion.  Yes it's complete syntactic sugar -- it doesn't do anything 
> you can't currently do, just does it in a much more friendly way -- but 
> incredibly helpful sugar ;)
> 
> Cheers!
> 
> Mike
> 
> ---------------------------------------------------------------------
> Mike Ford,  Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
> Email: m.ford@leedsmet.ac.uk
> Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211
> 
> 
> To view the terms under which this email is distributed, please go to 
> http://disclaimer.leedsmet.ac.uk/email.htm
