PHP Break - Code

PHP Foreach Loop Previous Next PHP Continue


Php Break statement is used to breaks one loop if a specified condition is true continue with the next loop.

Here is the code of php break statement.

Filename: php / break.php


Code
<?php
for($i=1;$i<=10;$i++){
if($i==6){
    break;
}
echo $i . "
"; } ?>

Running Step.


Type Url - https://localhost/php/break.php

Output
1
2
3
5

Break Without <br> Tag.


Break Without <br> tag will give output in same line called as inline.

Filename: php / break1.php


Code
<?php
for($i=1;$i<=10;$i++){
if($i==6){
    break;
}
echo $i;
}
?>

Running Step.


Type Url - https://localhost/php/break1.php

Output
12345

Break With While Loop


Below code show you how to use break in while loop

Filename: php / break-continue.php


Code
<?php
$i=1;
while($i<=7){
if($i==4){
    break;
}
echo $i . "
"; $i++; } ?>

Running Step.


Type Url - https://localhost/php/while-break.php

Output
1
2
3

Tags: PHP Break PHP Code Programming Language


Was this helpful ?

Related Code