PHP foreach并继续[关闭]

I've come across a function in some code I'm trying to debug and I'm not sure why it is written like this

foreach ($companies as $company) {
    if (!isset($company->account)) {
        continue;
    }
    some_function($company, $sectorsMap, $subSectorsMap);
}

Is this the same?

foreach ($companies as $company) {
    if (!isset($company->account)) {
        some_function($company, $sectorsMap, $subSectorsMap);
    }
}

How does the continue control structure work?

Cheers

If you made the if statements equivalent, I'd say the top version is more generic and better for more complex statements due to the following:

  1. If you had multiple if - continue statements, the first approach would allow you to list them in order without nested indentation which could keep your code cleaner. Using the second approach, you could get a lot of nested indentation.
  2. If you had a lot of code after the if - continue statement(s), the first approach would have the bulk of the code indented less and possibly easier to read.

In your specific example with one statement out side of the continue, it may not much difference, but if you were going to pick one approach to use everywhere, the first approach might be nicer for complex loops.