PHP Tutorial
What is PHP Environment Setup of PHP PHP Syntax PHP Comments PHP Echo & print PHP Variables PHP Scope Variables PHP $ and $$ Variable PHP Constants PHP Operators PHP Data TypesPHP Conditional Statements
PHP Loop Type
PHP Arrays
PHP String PHP FunctionsPHP Form Examples
Form Intro Get & Post Form Validation / Required PHP Complete FormPHP Advanced
PHP Include / Require PHP Date & Time PHP Session PHP Cookies PHP File Handling PHP Open File PHP Read File PHP Write File PHP Append File PHP Delete File PHP File Upload PHP Sending Mail PHP Error HandlingContinue or Break
break Statement in PHP?
The break statement in PHP is used to terminate the current flow of the program. The break statement is mostly used to break the execution of the for, while, do…while, foreach and switch statements on the basis of specified conditions.
The break
statement can also be used to jump out of a loop.
Example:
<?php
for ($i = 0; $i < 10; $i++)
{
if ($i == 4) {
break;
}
echo "The number is: $i <br>";
}
?>
This example jumps out of the loop when i is equal to 4:
Output:
The number is: 0
The number is: 1
The number is: 2
The number is: 3
continue Statement in PHP?
The continue statement in the PHP is used to iterate the loop by skipping the current flow when the condition is satisfied. When we want to go to the next iteration of a loop or switch control structure, we use the continue statement. The continue statement is mostly used to break the execution of the for, while, do…while foreach and switch statements on the basis of a specified condition.
Example:
<?php
for ($x = 0; $x < 10; $x++) {
if ($x == 4) {
break;
}
echo "The number is: $x <br>";
}
?>
This example skips the value of 4:
Output:
The number is: 0
The number is: 1
The number is: 2
The number is: 3
The number is: 5
The number is: 6
The number is: 7
The number is: 8
The number is: 9
Elevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date