For Loofs in PHP

In for-loop initialization, condition and increment happen on the same line. The loop keeps on repeating as long as the condition is true.

When the for loop is executed, the variable of the loop is initialized first and then the condition is checked. If the condition is true, then the program control goes to the statement block of the for loop and executes the statements there. When the For Loop statement executes all the statements in the block, it executes the step size part of the loop before exiting the block.
Then does the condition check back. If the condition is true then goes back to the statement block.

This sequence continues as long as the condition of the for loop remains true. Initialization of the loop happens only once.


for( initialization; condition;  increment ){


    echo "This is for loop in action <br>";

    for ($index=1; $index < 5; $index++) { 
        // for(initialization;condition; updation)
        echo "This number is $index <br>";

    echo "For loop has ended";


Related Posts

Associative Array in PHP?

An associative array is a simple and very important array of PHP. This array is also used the most, it is very easy to understand this array,…

How to work in functions PHP?

If there is any task in your program which you train to execute repeatedly then instead of writing the code for that task at a different place…

If Else Conditionals in Php?

If Else statement is the most important feature of any programming language, PHP is used to run any Code Of Block according to If Else conditions. This…

What are operators in PHP? PHP – Operator Types

Operators are used to developing data. In Programming Languages, Operators are taken from Mathematics and Operator Programmers work with Data. An operator is a chain of symbols…

String Functions in PHP?

When many characters are written together in sequence, they form a string. For example, India is a string. It is made up of i, n, d, i,…

What is the Variable And how does it work?

The variable is seen here as a container, which you can use to store data information. It doesn’t make any difference to him, so it becomes easy…

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x