continue not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Satterwhite

    continue not working

    I *MUST* be overlooking something obvious. Consider the following code:

    foreach($_POST as $key=>$value) {
    print "$key=>$value<b r />";
    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=>$keyLi st
    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?

  • Andy Hassall

    #2
    Re: continue not working

    On Sun, 26 Sep 2004 14:14:39 GMT, Michael Satterwhite
    <satterwh.X$NO$ S$PAM@weblore.c om> wrote:
    [color=blue]
    >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?[/color]



    "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 / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Michael Satterwhite

      #3
      Re: continue not working - THANKS

      Andy Hassall wrote:
      [color=blue]
      > On Sun, 26 Sep 2004 14:14:39 GMT, Michael Satterwhite
      > <satterwh.X$NO$ S$PAM@weblore.c om> wrote:
      >[color=green]
      >>I *MUST* be overlooking something obvious. Consider the following code:
      >> switch($key) {
      >> case "curKey":
      >> print "Matched exception<br />";
      >> continue;
      >> }
      >> print "Didn't bypass.<br />";[/color][/color]
      [color=blue]
      > Note: Note that in PHP the switch statement is considered a looping
      > structure for the purposes of continue.[/color]

      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.

      Comment

      Working...