PHP Break
نشر بتاريخ 2024-05-17 07:50:37
0
2كيلو بايت
The break
statement can be used to jump out of different kind of loops.
Break in For loop
The break
statement can be used to jump out of a for
loop.
ExampleGet your own PHP Server
Jump out of the loop when $x
is 4
:
for ($x = 0; $x < 10; $x++) {
if ($x == 4) {
break;
}
echo "The number is: $x <br>";
}
Try it Yourself »Break in While Loop
The break
statement can be used to jump out of a while
loop.
Break Example
$x = 0;
while($x < 10) {
if ($x == 4) {
break;
}
echo "The number is: $x <br>";
$x++;
}
Try it Yourself »Break in Do While Loop
The break
statement can be used to jump out of a do...while
loop.
Example
Stop the loop when $i
is 3:
$i = 1;
do {
if ($i == 3) break;
echo $i;
$i++;
} while ($i < 6);
Try it Yourself »Break in For Each Loop
The break
statement can be used to jump out of a foreach
loop.
Example
Stop the loop if $x
is "blue":
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $x) {
if ($x == "blue") break;
echo "$x <br>";
}
Try it Yourself »البحث
الأقسام
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- الألعاب
- Gardening
- Health
- الرئيسية
- Literature
- Music
- Networking
- أخرى
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
إقرأ المزيد
الثورة البلوكتشين وتحولاتها في الصناعات المختلفة
مقدمة: شهدت تقنية البلوكتشين ثورة هائلة في السنوات الأخيرة، حيث أصبحت لديها القدرة على تغيير...
PHP Array Functions
PHP Array Functions
PHP has a set of built-in functions that you can use on arrays....
PHP if Statements
Conditional statements are used to perform different actions based on different conditions....
PHP for Loop
The for loop - Loops through a block of code a specified number of times.
The PHP...
PHP if...else Statements
PHP - The if...else Statement
The if...else statement executes some code if a...