Foundations
Loops
Loops repeat a block while a counter changes.
Loops
loops.php
<?php
$limit = ;
$total = 0;
for ($number = 1; $number <= $limit; $number++) {
$total += $number;
}
echo "limit=" . $limit . "\n";
echo "total=" . $total . "\n";
<?php
$limit = ;
$total = 0;
for ($number = 1; $number <= $limit; $number++) {
$total += $number;
}
echo "limit=" . $limit . "\n";
echo "total=" . $total . "\n";
<?php
$limit = ;
$total = 0;
for ($number = 1; $number <= $limit; $number++) {
$total += $number;
}
echo "limit=" . $limit . "\n";
echo "total=" . $total . "\n";
for loop
A `for` loop can initialize a counter, test a condition, and update the counter after each pass.