Search code examples
phpforeachcontinue

In a PHP foreach, which is faster, negating condition or continuing?


Consider the following code:

foreach ($products as $product) {
    if (some_long_condition()) {
        continue;
    } 
    do_stuff();

Which would be faster, having a condition with a continue, or negating the condition itself? Is there a difference at all in terms of performance, or is it just syntactic sugar?


Solution

  • This is exactly the same, a boolean comparison. The compiler doesn't make a difference here.