PHP for_Loop

Back to ACP page

Table of Contents

PHP for_Loop

<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>"; } ?>

Example 1

Result View Example

PHP 2 break_Statement

<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>"; } ?>

Example 2

Result View Example

PHP 3 continue_Statement

<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>"; } ?>

Example 3

Result View Example

PHP 4 Step_10

<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>"; } ?>

Example 4

Result View Example

Document

Document in project

You can Download PDF file.

Reference