Why is a `switch` considered a looping structure for the purposes of `continue`?

I just got bit by assuming the following:

foreach ($arr as $key => $value) {
  switch($key) {
    // ... some other cases
    default:
      continue;
      // ^== assumption: move on to the next iteration of the foreach
      //     actual PHP: treat this continue just like a break
  }
  // ...
}

But in fact, according to the documentation for continue:

the switch statement is considered a looping structure for the purposes of continue.

Is there a reason for this choice on the part of PHP language designers? As far as I can tell, switch isn’t a looping control structure, so why treat it like one in this case?

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>