In this tutorial, you will learn PHP Break and Continue Statement.

हिंदी | PHP Break and Continue Statement in Hindi

PHP Break and Continue Statement


PHP Break Statement

The PHP break statement is used to stop or break a loop at a specific time or condition.

Keyword – break;

<?php
$data = [5,2,7,1,9,3];

foreach($data as $num){
    // if $num is equal to 7 then it will break the loop.
    if($num == 7){
        break;
    }
    echo $num."<br>";
}

echo "After running the loop.";
Browser Output
5
2
After running the loop.

PHP Continue Statement

The PHP continue statement is used to skip a specific iteration of a loop.

Keyword – continue;

<?php
$data = [5,2,7,1,9,3];

foreach($data as $num){
    // if $num is equal to 7 or 9 then it will skip the current iteration of the loop and go to the next iteration.
    if($num == 7 || $num == 9){
        continue;
    }
    echo $num."<br>";
}

echo "After running the loop.";
Browser Output
5
2
1
3
After running the loop.

Leave a Reply

Your email address will not be published. Required fields are marked *