#17556 [Com]: Docs lack specific info about switch() and continue;

From: Date: Mon, 29 Jul 2002 14:11:55 +0000
Subject: #17556 [Com]: Docs lack specific info about switch() and continue;
References: 1  Groups: php.bugs php.doc 
Request: Send a blank email to php-bugs+get-15494@lists.php.net to get a copy of this message
ID: 17556 Comment by: ahristov@icygen.com Reported By: ahristov@icygen.com Status: Bogus Bug Type: Documentation problem Operating System: All PHP Version: 4.2.1 New Comment: 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++; } Previous Comments: ------------------------------------------------------------------------ [2002-06-01 17:02:20] jmcastagnetto@php.net 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] ahristov@icygen.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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17556&edit=1

« previous php.bugs (#15494) next »