Skip to main content

Command Palette

Search for a command to run...

PHP For Loop Statements

Updated
1 min readView as Markdown
PHP For Loop Statements
E

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.

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

More from this blog

Javasper

50 posts

I'm a full stack software developer who loves to building new projects and solving difficult problems.

It might not be obvious from my posts, but I'm actually quite funny.