A for statement is often more efficient than a while statement, and achieves the same results. However, it does this succinctly, often using only one line of code, and is less likely to fall into the pit of creating an infinite loop. NOTICE: the expressions within the parentheses are separated by semi-colons. The first expression initializes a counter variable; the second expression creates the test condition; and the third expression increments (or decrements) the counter variable. If the test condition evaluates to true, the code block executes until the expression evaluates as false.
SYNTAX:
for (intitialization_expression; test_expression; modification_expression) {
// code to be executed
}
<?php
for ($counter=1; $counter<=12; $counter++) {
echo $counter." times 2 is ".($counter * 2)."<br />";
}
?>