Break and continue in for loop php - Break is used to terminate an executable of a loop control and a switch. While the continue is used to skip a defined loop and continue the iteration again.
To better understand the Break and Continue Structures in php looping, then the following I fill the example of application in a program.
Program
File Name: break.php
Description: Program Structure Break and Continue.
Open notepad then type the following code into notepad.
<?php
for ($i=1; $i<10; $i++) {
if ($i == 5)
continue;
if ($i == 8)
break;
echo "$i ";
}
?>
To better understand the Break and Continue Structures in php looping, then the following I fill the example of application in a program.
Program
File Name: break.php
Description: Program Structure Break and Continue.
Open notepad then type the following code into notepad.
<?php
for ($i=1; $i<10; $i++) {
if ($i == 5)
continue;
if ($i == 8)
break;
echo "$i ";
}
?>
If so, save the code into the htdocs folder named break.php.
Program Explanation
From the above program, it can be concluded that the continue command will continue the looping process without passing (executing) the command line underneath. So the command on line 6-8 will be skipped (5 will not print). While the breakakan command causes the program to stop the iteration (directly out of the iteration)
To see the results, please open the browser type http://localhost/break.php in the address bar. Then the result will look like the following.
![]() |
Program View |
That's the article about Break and continue in for loop php that we can share with you. Hopefully can improve our ability in studying php programming language.
Comments
Post a Comment