Skip to main content

PHP For Loop Statements

Updated 1 min readMarkdown
PHP For Loop Statements

A for loop executes the code block for a set number of iterations. This loop has the following syntax.

<?php
for($i=0; $i<100; $i++)
{
//code block
}
?>

$i is the counter. The first part specifics the starting value of the counter. The second part specifies the condition when you want the loop to stop. The third part specifies what code you want to execute once you get execute to the bottom of the {} section. Generally, you simply write $i++ meaning “when you hit the bottom of the section, you increase the counter by 1.” The loop will keep iterating until the condition in the second part is met. Example

<?php
for($i=0; $i<20; $i++)
{
echo $i;
echo "<br>";
}
?>

Result

1.png

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