ID: 17556 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Bogus Bug Type: Documentation problem Operating System: All PHP Version: 4.2.1 New Comment:
With respect to what you "wanted to say", your second example is not what you explained in your original report. Be more careful with your wording or include an example that clarifies your report. If you re-read your first report there is *no mention at all* of the case where switch is inside a loop (while, for, etc.) Also, your logic does not seem too clear to me in your example. What is the *exact* intended effect?, perhaps that the "continue" goes to the top of the while loop even though it is *not* in the current scope of that block but in the switch block, that will be an odd behaviour indeed. If you can be: (a) more precise w/ respect to the execution flow, (b) provide some examples of other scripting languages where the switch supports a continue that behaves like you are mentioning here, (c) explain why such a construct is desirable instead of the more logic one of doing a break in the switch block and perfoming the conditional comparison outside the switch block, so you are not dependent on side-effects (which can be tricky to debug later on) Then there will be a good change to reopening this bug. Will wait for your feedback, but will not reclassify this out of "Bogus" for the time being. Previous Comments: ------------------------------------------------------------------------ [2002-07-29 10:11:54] [EMAIL PROTECTED] 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++; } ------------------------------------------------------------------------ [2002-06-01 17:02:20] [EMAIL PROTECTED] Ehem, the documentation for "switch" explicitly says: "... The switch statement is similar to a series of IF statements on the same expression ..." And I do not know of any language that uses a series of if statements as a loop construct (that is why for, while and do ... while are there). If you know of one, I will be interesting to check it out to see how that can be done. Also, nowhere there is mentioned that "continue" can be used to loop in a non-looping construct (e.g. if), and if you read again the the description of "continue" it says: "continue is used within looping structures to skip the rest of the current loop iteration and continue executio at the beginning of the next iteration" thus if you use that in a context where there is no loop, it just gets out of scope. This is (or should) something learned in basics of programming book, article, etc. ------------------------------------------------------------------------ [2002-06-01 15:12:51] [EMAIL PROTECTED] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17556&edit=1 -- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php