, I'd like to turn the topic to a completely
different language
feature which (might) please enough people to get a rousing consensus.Actual labeled breaks. Not the break+jump that was proposed
earlier in the
guise of a break statement, but an actual straightforward, no
funny-business labeled break which does no more and no less than the
current break N; construct, but allows the use of identifier labels
rather
than numbers which
may change as the result of the addition or removal of break
containers.
Well, as this is exactly what I proposed just yesterday, I'm + several thousand for it (modulo my fairly nonexistent karma!). I'd love to see this implemented regardless of what happens to goto, as I completely don't care whether PHP has goto or not.
http://libssh2.org/patches/true_labeled_break.diff
Usage:
while FOO ($condition) {
/* statements /
break FOO;
/ more statements */
}Or a stacked example:
for FOO(;;) {
while BAR (true) {
foreach BAZ ($arr as $val) {
switch Foof ($value) {
default:
do Plop {
break FOO;
} while (false);
}
}
}
}
I'm fairly agnostic on which syntax to use, although I see some benefit in distinguishing break labels from goto labels. I do quite like the "as" suggestion -- it seems really clear and readable.
- Labels can be repeated by siblings. I'm not married to this, and it
certainly has WTF potential.
Mmmm -- not too sure about this. As you say, it possibly has slightly too much WTF potential.
- Labeled breaks also apply to continue; For example:
Of course. I thought that went without saying. ;)
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