Home of web learners


For loop is very popular and most used loop

Difference between other loop and for loop is about declaration and increment style

Lets look an example

for ($x = 0; $x < 5; $x++) {
echo $x;



Here,we see that $x=0 is iniialization part,here we assign the start of variable by which for loop is going to work

Then we divide 3 parts of loop,initialization,condition check,increment/decement part by ;

In the second part of for loop,we use condition,here we want to work this for loop up to less than 5,means 4

And in the third part,we use increment,where it x value increment by 1 as $x++ means add 1 with previous value of $x

Then in the body part of for loop,which start with { and end with }

Inside this the work for each interation is going to work

Here,we only show the value of x,so we can see the increment of x value here

So,in the body part you can use the code which you want to repeat many times can do with for loop


About webn3rd