By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,713 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,713 IT Pros & Developers. It's quick & easy.

continue not working

P: n/a
I *MUST* be overlooking something obvious. Consider the following code:

foreach($_POST as $key=>$value) {
print "$key=>$value<br />";
if(! empty($value)) {
switch($key) {
case "Submit":
case "keyList":
case "curKey":
print "Matched exception<br />";
continue;
}
print "Didn't bypass.<br />";
.......

Among the form display is:

keyList=>$keyList
Matched exception
Didn't bypass.

Obviously, the "switch" statement was properly matched as it shows it
matched the test expression. The next statement is a "continue", which
should have gone to the next statement in the loop, but it DIDN'T. It's as
if the "continue" statement was ignored. What am I missing?

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sun, 26 Sep 2004 14:14:39 GMT, Michael Satterwhite
<sa*****************@weblore.com> wrote:
I *MUST* be overlooking something obvious. Consider the following code:
switch($key) {
case "curKey":
print "Matched exception<br />";
continue;
}
print "Didn't bypass.<br />";
.......

Obviously, the "switch" statement was properly matched as it shows it
matched the test expression. The next statement is a "continue", which
should have gone to the next statement in the loop, but it DIDN'T. It's as
if the "continue" statement was ignored. What am I missing?


http://uk.php.net/manual/en/control-...s.continue.php

"continue

continue is used within looping structures to skip the rest of the current loop
iteration and continue execution at the beginning of the next iteration.

Note: Note that in PHP the switch statement is considered a looping
structure for the purposes of continue.

continue accepts an optional numeric argument which tells it how many levels of
enclosing loops it should skip to the end of.
"

So "continue 2" to get out of the switch and also the enclosing loop?

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
Andy Hassall wrote:
On Sun, 26 Sep 2004 14:14:39 GMT, Michael Satterwhite
<sa*****************@weblore.com> wrote:
I *MUST* be overlooking something obvious. Consider the following code:
switch($key) {
case "curKey":
print "Matched exception<br />";
continue;
}
print "Didn't bypass.<br />";
Note: Note that in PHP the switch statement is considered a looping
structure for the purposes of continue.


Thanks. While I can't think of a rational reason that a switch should be
considered a loop, there is no rule that says I have to understand it. <g>

Appreciate the help.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.