Re: switch() and default:
| From: | Andi Gutmans | Date: | Fri, 08 Oct 2004 18:31:32 +0000 |
| Subject: | Re: switch() and default: | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13240@lists.php.net to get a copy of this message | ||
I don't think we should do anything about it. From day 1 we treated switch() like a loop as far as break/continue is concerned, mainly because we wanted break/continue to be consistent. You might find this odd but you actually have more power in PHP than in C as you can break out or continue from multiple loops.
In my opinion this is definitely not something which should be changed at this point.
BTW, I think we have a fix for the switch() thingy. I still have to look at it more closely before commiting though.
Andi
At 05:37 PM 10/8/2004 +0100, Wez Furlong wrote:
Slightly OT, but while we are on the subject of switch not being
C-ish, how about making it so that continue inside a switch block
behaves the way it does in C?
This C code snippet:
while (1) {
printf("top\n");
switch (1) {
case 1:
continue;
}
printf("bork\n");
}
will print out "top\n" repeatedly.
The same code in PHP will print out "top\nbork\n" repeatedly.
The get the same behaviour as the C code you need to use continue 2 instead.
IMO, this is awful, and at first I thought it was a BC break, but it
seems that the stock RHEL 4.3.2 version of PHP behaves the same way.
What, if anything, should we do about this?
--Wez.