Table of Contents
<h2>PHP for Loop</h1>
<p>The for loop is used when you know how many times the script should run.</p>
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
Result View Example
<h2>PHP for Loop - break_Statement</h1>
<p>With the break statement we can stop the loop even if the condition is still true:</p>
<?php
for ($x = 0; $x <= 10; $x++) {
if ($x == 3) break;
echo "The number is: $x <br>";
}
?>
Result View Example
<h2>PHP for Loop - continue_Statement</h1>
<p>With the continue statement we can stop the current iteration, and continue with the next:</p>
<?php
for ($x = 0; $x <= 10; $x++) {
if ($x == 3) continue;
echo "The number is: $x <br>";
}
?>
Result View Example
<h4>PHP for Loop - Step 10</h4>
<p>This example counts to 100 by tens:</p>
<?php
for ($x = 0; $x <= 100; $x+=10) {
echo "The number is: $x <br>";
}
?>
Result View Example
Document in project
You can Download PDF file.