
PHP Jumping Statements are used to jump out from a loop or jump the controller from one line to another line, inside a program.
PHP break is a keyword, which is used to terminate the execution of a loop.
Example 1: PHP Break Statement
<html>
<body>
<?php
for($i=1; $i<=10; $i++)
{
if($i==5)
break;
echo "For Loop $i<br>";
}
?>
</body>
</html>
PHP Continue statement is used to skip the current iteration of a loop but it does not terminates the loop.
Example 2: PHP Continue Statement
<html>
<body>
<?php
for($i=1; $i<=10; $i++)
{
if($i==5)
continue;
echo "For Loop $i<br>";
}
?>
</body>
</html>
It will skip 5th statement
PHP goto statement is also a jumping statement, and it is use to jump any section or any line in the program using user defined label.
Example 3: PHP goto Statement
<?php
echo "<div>First Line</div>";
goto bottom;
echo "<div>Second Line</div>";
bottom:
echo "<div>Third Line</div>";
?>
Example 4: PHP goto Statement
<?php
$i=1;
top:
echo "<div>".$i++."</div>";
if($i<6)
goto top;
?>
Example 5: PHP goto statement inside loop.
<?php
for ($i=1; $i<=5; $i++)
{
echo $i."<br>";
goto outloop;
}
outloop:
echo "Program ends";
?>
Example 6: PHP goto statement inside loop.
<?php
goto inloop;
for ($x=1; $x<=5; $x++)
{
inloop:
echo $x."<br>";
}
?>
Ad: