Home > Backend Development > PHP Tutorial > PHP implementation method of using continue to skip the remaining code in the loop

PHP implementation method of using continue to skip the remaining code in the loop

小云云
Release: 2023-03-20 08:42:02
Original
1649 people have browsed it

The continue jump statement is used to skip the statement specifying the condition in this loop and continue to execute other loop statements. As we all know, in PHP, continue is used in loop structures to skip the remaining code in this loop and start executing the next loop when the condition evaluates to true. It must be noted that when using continue, you must use ";" to separate other codes, otherwise it may cause errors!

continue Usage:

<?php
for ($n = 0; $n < 5; $n++) {
 if ($n == 2)
  continue;
  echo "$n\n";
}
?>
Copy after login

Output result:

0 1 3 4

Obviously, when $n is equal to 2, it is skipped The output is exactly what we want. If the semicolon is missing, an error will be reported!

Error code:

<?php
for ($n = 0; $n < 5; $n++) {
 if ($n == 2)
  continue
  echo "$n\n";
}
?>
Copy after login

Error message:

Parse error: syntax error, unexpected 'echo' (T_ECHO) in D:\phpStudy\WWW\demo\fun \continue.php on line 5

So note: when we use continue, we must be careful not to miss the semicolon!

Related recommendations:

Detailed explanation of the difference between break and continue in javaScript

PHP uses continue to skip this Notes on the remaining code in the secondary loop

php break and continue statements, goto statements and php constants

The above is the detailed content of PHP implementation method of using continue to skip the remaining code in the loop. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template