July 25, 2017

Core PHP: The For Loop (5.9)

The for Loop


The example below displays the numbers from 0 to 5:
for ($a = 0; $a < 6; $a++) {
   echo "Value of a : ". $a . "<br />";
}

Result:
Example: The for loop


The for loop in the example above first sets the variable $a to 0, then checks for the condition ($a < 6). If the condition is true, it runs the code. After that, it increments $a ($a++).

No comments:

Post a Comment