PHP 4.0 Bug #8428 Updated: continue doesn't pass thru a switch statement

From: Date: Sat, 06 Jan 2001 04:04:16 +0000
Subject: PHP 4.0 Bug #8428 Updated: continue doesn't pass thru a switch statement
Groups: php.dev 
Request: Send a blank email to php-dev+get-43122@lists.php.net to get a copy of this message
ID: 8428 Updated by: zak Reported By: ocomte@guarantycity.com Old-Status: Bogus Status: Open Old-Bug Type: Unknown/Other Function Bug Type: Feature/Change Request Assigned To: Comments: The desired behavior is that continue is transparent to switch statements - this behavior would mimic how if handles continue statements. Previous Comments: --------------------------------------------------------------------------- [2001-01-05 22:33:45] zak@php.net The switch statement is a flow control construct - like for or if. Because of this continue behaves within switch like it should in any flow control contruct - it skips to the next loop of the construct. However, switch does not loop - so continue behaves like break. If you would like to use a continue embedded in a switch statement to continue past a loop in an outside control construct, specify how many levels you would like continue to break out of. Try these examples to see what I mean: <pre> <?php for ($i=0; $i<5; ++$i) { switch(1) { case 1: continue 2; break; } echo "Should be skipped"; } // Should not output anything for ($i=0; $i<5; ++$i) { for ($z=10; $z>5; --$z) { switch(1) { case 1: continue 2; break; } echo "$z=$zn"; } echo "$i=$in"; } /* Should output: $i=0 $i=1 $i=2 $i=3 $i=4 */ ?> --------------------------------------------------------------------------- [2000-12-26 13:34:59] ocomte@guarantycity.com in the script : <? for($i=0; $i<5; ++$i) { switch(1) { case 1: continue; } echo "Not printable"; } ?> the string is printed 5 times because the continue statement end the switch (like break). In C and C++, and in the PHP manual the continue (unlike break) isn't affected by surrounding switch statement and it seems logical to me. --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=8428

« previous php.dev (#43122) next »