Req #33034 [Opn->Csd]: continue behavior in switch has a potential use
| From: | kalle@php.net | Date: | Fri, 19 Jun 2015 13:40:21 +0000 |
| Subject: | Req #33034 [Opn->Csd]: continue behavior in switch has a potential use | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193693@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=33034&edit=1
ID: 33034
Updated by: kalle@php.net
Reported by: sadmac at earthlink dot net
Summary: continue behavior in switch has a potential use
-Status: Open
+Status: Closed
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Windows XP
PHP Version: 4.3.11
-Assigned To:
+Assigned To: kalle
Block user comment: N
Private report: N
New Comment:
You can omit the break statement to fall-through to the underlaying segment, but I don't see
how it can be possible in a reasonable way to achieve skipping certain segments in the switch
statement.
Although I'm not sure why you would want to achieve your example with a switch-statement, and
not a simple if condition, since if what happens in 'case 0' (top part) doesn't have
anything to do with what happens in 'case 1' and jumps straight pass it, if you absolutely
need that logic to be shared, then it should be done in a function call or something, as of 5.3 you
can even use goto! (no joke intended)
Previous Comments:
------------------------------------------------------------------------
[2008-03-07 12:55:52] packard_bell_nec at hotmail dot com
I also like this feature proposal, because it can simplify the coding VERY much. It can eliminate
the repeating checkups, statements, or even functions. In addition, it can increase the readability.
------------------------------------------------------------------------
[2005-05-15 03:35:04] sadmac at earthlink dot net
Description:
------------
When the user uses continue in a switch, it behaves essentially the way a break behaves. However,
the name might imply (and I already have use for this feature) that the switch statement would then
continue evaluating cases, and execute any code under another case statement further down in the
switch which fit the condition.
Reproduce code:
---------------
<?php
$j = 0;
switch($j)
{
case 0:
echo "part one ";
break;
case 1:
//blah blah blah
break;
case 0:
echo "part two";
break;
} //Will only ouput "part one"
switch($j)
{
case 0:
echo "part one ";
continue;
case 1:
//blah blah blah
continue;
case 0:
echo "part two";
continue;
} //Should potentially output "part one part two"
?>
Expected result:
----------------
The first statement should behave as it currently would, the second should evaluate both case 0s,
not just the first.
Actual result:
--------------
Both switches evaluate only the first case 0.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=33034&edit=1