
Colin Viebrock, CC BY-SA 4.0, via Wikimedia Commons
A while loop executes a certain block of code until a particular condition is no longer true. Syntax
<?php
while(conditional)
{
//code block
}
?>
A while loop says as long as this condition inside the brackets () is true, keep executing the code block inside of {}.
Example
<?php
$i=0;
while($i<10)
{
echo $i;
echo "<br>";
echo $i++;
}
?>
Result
Your while loop should have inside it 1) a counter and 2) a way of increasing the counter.
Otherwise, your loop will keep repeating forever without a way to end.
About the author
I'm a full-stack web developer who loves building new projects and learning new things
It might not show from my posts, but I'm also quite funny.
Comments
Join the discussionNo comments yet. Be the first to comment.




