Skip to main content

PHP While Loop Statements

Updated 1 min readMarkdown
PHP While Loop Statements

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

1.png 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.

No comments yet. Be the first to comment.

More from this blog