|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-06-01 15:12 UTC] ahristov at icygen dot com
After 2 years of coding in PHP I found something strange to me but probably not to the creators of PHP :)). continue; inside a switch statement is equivalent of break; For this reason I've found 3 closed bugs - 5805, 8768 & 7591. However there is no info in the docs that switch() is one time loop - as said in one of the answer of one of the reports. I think that switch() docs has to mention that switch() is works like one iteration loop and that continue without any params within a switch is equivalent of break;. Thus the effect which one may want will be continue (level+1) (level is the level which will be if the program was written in C). Finally there should be short note in the continue; docs that inside a switch() it works somekind different than in C and provided link to switch() page for more info. Best regards, Andrey Hristov PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 07:00:02 2025 UTC |
I think that Mr Jesus Catagnetto misunsterstood what I am talking about. IMO the bug must be reopened. I just wanted to say that while (some){ switch ($foo){ case 'bar': if (some_reason) continue;//ie next iteration, but no, it will increment counter after the switch. Must be continue(2); break; case 'boo': // break; default: break; } echo $counter++; }Here are two examples: <?php $counter = 0; while ($counter<20){ switch ($counter){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: $counter++; break; default: $counter+=2; continue; }// swhitch echo 'FUBAR'."[$counter]\n"; }//while ?> <?php $counter = 0; while ($counter<20){ switch ($counter){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: $counter++; break; default: $counter+=2; continue(2); }// switch echo 'FUBAR'."[$counter]\n"; }// while ?> The intention is to show that there is no note in the docs for that when programmer wants to go to the next iteration of the loop that is shell to the switch() he/she must use continue(2); not continue;. This is because in switch()-es continue; is equivalent to break; In general if programmer want to skip the rest of the n-th loop (counted from the most inner to most outter) he must use continue(n+1); and not contunie(n); If there is something hard to get (beacuse of my english) please contact me and I will explain. Regards, Andrey Hristov