Tutorials

Learn web design and programming with our free video and text tutorials.

Web Designer? Design and market your own professional website with easy-to-use tools.

PHP for Loops Tutorial

PHP for loops execute a block of code a specified number of times.

<?php
for($a=0; $a<10; $a++) {
echo "This statement was executed $a times.<br />";
}
?>

The code above outputs:

This statement was executed 0 times.
This statement was executed 1 times.
This statement was executed 2 times.
This statement was executed 3 times.
This statement was executed 4 times.
This statement was executed 5 times.
This statement was executed 6 times.
This statement was executed 7 times.
This statement was executed 8 times.
This statement was executed 9 times.