Control Flow Details
While Loops
A while loop repeats while its condition remains true.
While Loops
while_loop.php
<?php
$start = ;
$current = $start;
$total = 0;
while ($current > 0) {
$total += $current;
$current--;
}
echo "start=" . $start . "\n";
echo "total=" . $total . "\n";
echo "current=" . $current . "\n";
<?php
$start = ;
$current = $start;
$total = 0;
while ($current > 0) {
$total += $current;
$current--;
}
echo "start=" . $start . "\n";
echo "total=" . $total . "\n";
echo "current=" . $current . "\n";
<?php
$start = ;
$current = $start;
$total = 0;
while ($current > 0) {
$total += $current;
$current--;
}
echo "start=" . $start . "\n";
echo "total=" . $total . "\n";
echo "current=" . $current . "\n";
while condition
The condition is checked before each loop pass.