On Sat, 2002-02-23 at 20:13, KAT 44 wrote: > Hello, > I'm not sure if this is a newsgroup, list or direct e-mail > address. In any case, I ask of anybody who can answer my > question to *send me an e-mail* at [EMAIL PROTECTED], > and not answer on the list/newsgroup/etc. (Thank you.)
I'm replying to you *and* to the list, in case the information might be useful to others. ;) > My question is the following: > When having a switch statement as follows: > switch($value) { > case something: > if(condition) { > do_my_stuff; > } else { > continue; > } > case something_else: > do_my_other_stuff; > default: > show_error_message; > } > Does the continue continue on evaluating (and comparing) > $value to the case statements, or does it give control to > the default: statement? > Simpler put: > Does a "continue" statement within a "switch" statement > pass control to that "switch" statement's "default:" > section? > Thanks, > KAT44 Well, my first question is: what happens when you try it? Inside a switch(), a continue works exactly the same as a break, *as long as it has no arguments*. Numeric arguments to continue then apply to any containing looping structures--treating the switch() as the first. For more information on continue, and its optional arguments, see http://www.php.net/continue. For a simple test case, try the following test script and compare it to the expected output. ---script--- <?php error_reporting(E_ALL); $case = 'bar'; switch ($case) { case 'foo': echo "foo\n"; break; case 'bar': echo "bar\n"; continue; default: echo "default\n"; } for ($i = 0; $i < 10; $i++) { echo "Start of for() loop; item $i: "; switch ($i) { case 1: echo "$i: foo\n"; continue 2; case 2: echo "$i: bar\n"; continue 2; default: echo "$i: default\n"; } echo "End of for() loop\n"; } ?> ---output--- bar Start of for() loop; item 0: 0: default End of for() loop Start of for() loop; item 1: 1: foo Start of for() loop; item 2: 2: bar Start of for() loop; item 3: 3: default End of for() loop Start of for() loop; item 4: 4: default End of for() loop Start of for() loop; item 5: 5: default End of for() loop Start of for() loop; item 6: 6: default End of for() loop Start of for() loop; item 7: 7: default End of for() loop Start of for() loop; item 8: 8: default End of for() loop Start of for() loop; item 9: 9: default End of for() loop Hope this helps, Torben -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php