while
LoopThe while
statement will execute the nested statement(s) repeatedly as long as the condition specified in the while
statement evaluate to true.
while (condition){ // statement to be executed repeatedly // as long as the condition is TRUE. }
The following examples print the numbers 1 through 10. The loop will continue to run as long as $i is less than or equal to 10. The $i will increase by 1 each time the loop runs:
<?php $i = 1; while ($i <= 10) { echo $i; $i++; } ?>
while
loop statementIn while
loop statement, We can change the opening brace to a colon:
and the closing brace to endwhile
;
<?php $i = 1; while ($i <= 10): echo $i; $i++; endwhile; ?>