Learn PHP Programming

A backend server scripting language, and a powerful tool for making dynamic and interactive Web pages. Learn each topic with examples and output.

PHP Introduction
Control Structures
Php Forms
Php Advanced

PHP Break Statement

In PHP, the break statement is used in loops (such as for, foreach, while, and do...while loops) and switch statements to exit the loop or switch statement prematurely. The break statement allows you to control the flow of the program by terminating the loop or switch when a certain condition is met. Here's how the break statement is typically used:

Using break in for loop:

    for ($i = 1; $i <= 10; $i++) {
        if ($i == 5) {
            break; // Exit the loop when $i is equal to 5
        }
        echo $i . " ";
    }
1 2 3 4

Next chapter is Continue Statement


Share this page on :

=