unknown os platform
Free Beginner PHP Tutorials - For loop | Whats-online.info
whats-online-info

Free Beginner PHP Tutorials - For loop


Free
2016:09:26 / Science and Tutorials

PHP For Loop basically, is used to built repetitive task within a program to save time. See example:-





PHP For Loop


PHP For Loop executes a block of code over a specified number of times.
PHP for loop is used when the number of times the script should run is specified, unlike other programming languages where the variable length is defined by using the function variable.length().

Syntax

for (initialize counter; test counter; increment counter) {     execute code; }

Parameters:
-Initialize counter - Initializes the loop counter value. Marks the first value where the loop should begin.
-Test counter  Evaluated for each loop iteration. Test for the condition if it evaluates to true, the loop continues otherwise the loop ends if it evaluates to FALSE.
-increment counter: Increases the loop counter value.

Example:

<?php   $sum=0; for($i = 0; $i <= 10; $i++ ){     $sum += $i; }     echo "The sum of the first ten numbers ".$sum; ?>

The example above finds the sum of the first ten letters. Also, you can use other loop statements to work out the example above.

See also:













You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment