0

I knew that we use continue to jump to the next iteration in loop

For example

$x = 0;
for( $i = 0; $i < 10; $i++ ) {
  if( $i%2 == 0 ) {
    continue;
  }
  $x = $x + $i;
}

In this case we use continue to skip the even number, but we can do this instead

$x = 0;
for( $i = 0; $i < 10; $i++ ) {
  if( $i%2 != 0 ) {
    $x = $x + $i;
  }
}

Can anyone show me some cases that we MUST use continue instead of only using opposite condition.

Luu Hoang Bac
  • 433
  • 6
  • 17
  • 1
    Does this answer your question? [Difference between break and continue in PHP?](https://stackoverflow.com/questions/4364757/difference-between-break-and-continue-in-php) – Pouya Heydari Feb 27 '21 at 05:32
  • 2
    `continue` is not mandatory, it is up to the developer whether to use it or not. – nice_dev Feb 27 '21 at 05:58

0 Answers0