Home > Backend Development > PHP Tutorial > The difference between continue break exit return in php

The difference between continue break exit return in php

藏色散人
Release: 2023-04-07 18:38:02
forward
3414 people have browsed it

The loops in php include for foreach while do{} whlie.

1, continue

continue is used in the loop structure to control the program to give up the current loop continue; the statement after

, and transfer And enter the next cycle.

continue itself does not jump out of the loop structure but just gives up this loop.

Note: If continue is used in a non-loop structure (if switch), it will cause a program error.

2. break

The function of break is to jump out of the current syntax structure. The break statement can take a parameter n, indicating the number of layers to jump out of.

3. exit

exit ends program execution and can be used anywhere.

4. return

The return statement is used to end a piece of code and return a parameter.

If used in the main program, the main program will stop execution immediately.

For example:

<?php
for($i = 1000;$i >= 1 ; $i-- ){
if( sqrt($i) >= 30){
    echo $i."</br>";
}
else{
    return;
}
}
echo"本行将不会被输出";
Copy after login

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of The difference between continue break exit return in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:segmentfault.com
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